以下警告显示在我的项目中 -
未选中调用'getWeatherData(T,Boolean,String)'作为原始类型'IWeatherCallbackListener'的成员.
我创建了以下界面 -
public interface IWeatherCallbackListener<T> {
void getWeatherData(T weatherModel, Boolean success, String errorMsg);
}
Run Code Online (Sandbox Code Playgroud)
并按以下方式调用它,
public class WeatherConditions {
private static IWeatherApi mWeatherApi;
/**
* @param city
* @param appId
* @param listener
*/
public static void getOpenWeatherData(String city, String appId, IWeatherCallbackListener listener) {
mWeatherApi = ApiService.getRetrofitInstance(BASE_URL_OPEN_WEATHER).create(IWeatherApi.class);
Call<OpenWeatherModel> resForgotPasswordCall = mWeatherApi.getOpenWeatherData(appId, city);
resForgotPasswordCall.enqueue(new Callback<OpenWeatherModel>() {
@Override
public void onResponse(Call<OpenWeatherModel> call, Response<OpenWeatherModel> response) {
if (response.body() != null) {
if (listener != null)
listener.getWeatherData(response.body(), true, "");
}
} …Run Code Online (Sandbox Code Playgroud) 我想使用最新的融合位置提供商客户端在"后台服务"上获取位置更新.我不想使用所有正在使用的位置监听器和Google API客户端.我还需要使用谷歌播放服务提供的位置设置Api来检查位置设置是否禁用或启用"后台服务".请帮助.
android android-location google-play-services fusedlocationproviderapi google-location-services
Value我在数据类下为 json 字段创建了一个密封类CustomAttribute。该字段可以返回String或Array of Strings。
我们如何从 json 反序列化这个密封类?
data class CustomAttribute (
val attributeCode: String,
val value: Value
)
sealed class Value {
class StringArrayValue(val value: List<String>) : Value()
class StringValue(val value: String) : Value()
}
Run Code Online (Sandbox Code Playgroud) 当用户进入已定义的地理围栏区域时,我正在使用意图服务来创建通知.问题是,当我第一次运行应用程序时,它工作正常,我在意向服务上获得待定意图,但几天后( 2-3),我没有获得意向服务所需的意图.
我不知道为什么它会在几天后停止工作.如果我启动应用程序,它将再次正常启动,但在几天后再次停止.
这是我的活动代码 -
public class MainActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks, ResultCallback, OnRequestPermissionsResultCallback {
GoogleApiClient mGoogleApiClient;
Location mGeoLocation;
Geofence mGeofence;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION}, 100);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码在导航抽屉中添加页脚视图 -
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nv_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|start">
<androidx.core.widget.NestedScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/nav_header_main"/>
<com.google.android.material.navigation.NavigationView
android:id="@+id/drawer_menu_body"
app:elevation="0dp"
android:layout_height="0dp"
android:layout_width="wrap_content"
android:layout_weight="1"
app:menu="@menu/activity_main_drawer">
</com.google.android.material.navigation.NavigationView>
<include layout="@layout/navigation_drawer_bottom_view"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
但是现在 onNavigationItemSelected() 没有调用导航抽屉也保持打开状态,直到我们手动滑动它。我正在使用导航组件和导航图。
这是我的活动代码 -
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar)
val navController = findNavController(R.id.nav_host_fragment)
drawer_menu_body.setNavigationItemSelectedListener(this)
nv_top.setNavigationItemSelectedListener(this)
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.nav_home,
R.id.nav_gallery,
R.id.nav_slideshow,
R.id.nav_tools,
R.id.nav_share, …Run Code Online (Sandbox Code Playgroud) android ×6
drawable ×1
generics ×1
geofencing ×1
geometry ×1
gson ×1
interface ×1
java ×1
json ×1
kotlin ×1
layer-list ×1
menu ×1
navigation ×1
photos ×1
scroll ×1
sealed-class ×1
shapes ×1
timeline ×1