Java GPS定位已启用,但可以';找不到设备位置
即使启用了位置,应用程序仍停留在白色对话框中。 关于位置责任,有两个文件如下所述Java GPS定位已启用,但可以';找不到设备位置,java,android,android-studio,location,Java,Android,Android Studio,Location,即使启用了位置,应用程序仍停留在白色对话框中。 关于位置责任,有两个文件如下所述 提醒Activity.java: 上述相同内容在rementactivity.java中编写如下: 提醒Activity.java: 这是一个注册的屏幕&这个位置在某些设备上有效,但在所有设备上不起作用(正如我测试的那样)。 即使启用了位置,应用程序仍停留在白色对话框中 如何解决这个问题。 提前感谢。如果您只想检查应用程序在前台时是否启用了位置,请使用下面的方法 启动“位置源设置”后,关闭对话框并在“活动”
上述相同内容在rementactivity.java中编写如下:
提前感谢。如果您只想检查应用程序在前台时是否启用了位置,请使用下面的方法 启动“位置源设置”后,关闭对话框并在“活动”中显示一些刷新按钮。单击“刷新”按钮时,再次重新创建“活动”
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
finish();
}
//in your activity
public void onRefresh() {
reCreate();
}
}
使用服务不断检查有关Gps的信息。@IDLERNER如何做,兄弟…请指导我
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();
}
}
@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();
}
}
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
finish();
}
//in your activity
public void onRefresh() {
reCreate();
}
}