很抱歉问这个,但我不是一个android应用程序的开发人员。我想问一个自定义的地理定位android应用程序是否可以这样编码,当用户启动应用程序并检测到设备的定位服务关闭时,它将显示为提示,或者应用程序将不会继续,直到用户手动打开定位服务?
我们正在使用移动设备管理( mdm )来管理android移动设备,但mdm没有执行位置服务设置的功能。
自定义地理定位android应用程序需要启用定位服务才能正常工作。
发布于 2021-11-17 16:06:51
您可以检查GPS是否已启用,如果未启用,将显示一条消息
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//here do what you want when the GPS service is enabled
Toast.makeText(MainActivity.this, "is enable", Toast.LENGTH_SHORT).show();
} else {
MaterialAlertDialogBuilder locationDialog = new MaterialAlertDialogBuilder(MainActivity.this);
locationDialog.setTitle("Attention");
locationDialog.setMessage("Location settings must be enabled from the settings to use the application");
locationDialog.setCancelable(false);
locationDialog.setPositiveButton("Open settings", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
});
locationDialog.create().show();
}
}
}
https://stackoverflow.com/questions/70005466
复制相似问题