【发布时间】:2021-05-30 13:31:47
【问题描述】:
应用程序卡在白色对话框中,即使在启用位置后也是如此。 如下所述,有两个文件用于定位责任。
- RemindActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.remind_activity);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
.
.
.
LocationPremissionCheck();
GooglePlayServiceCheck();
GPSLocationServiceCheck();
.
.
.
}
private void GPSLocationServiceCheck() {
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Your GPS seems to be disabled, enable it to use this app?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
dialog.cancel();
Intent intent = new Intent(RemindActivity.this, StartActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
}
上面同样的东西写在RemindActivity.java中如下:
- RemindActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.remind_activity);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
.
.
.
LocationPremissionCheck();
GooglePlayServiceCheck();
GPSLocationServiceCheck();
.
.
.
}
private void GPSLocationServiceCheck() {
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Your GPS seems to be disabled, enable it to use this app?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
dialog.cancel();
Intent intent = new Intent(RemindActivity.this, StartActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
}
这是一个注册屏幕,此位置适用于某些设备,但不适用于所有设备(正如我测试的那样)。 应用程序卡在白色对话框中,即使在启用位置后也是如此。
如何解决此问题。 提前致谢。
【问题讨论】:
-
使用服务不断检查Gps。
-
@androidLearner 如何做到这一点兄弟...请指导我
标签: java android android-studio location