【发布时间】:2016-01-22 14:13:39
【问题描述】:
我正在尝试通过用户确认对话框来启用 GPS 设置。
这里是代码
public void turnGPSOn() {
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean enabled = service
.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabled) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
this);
alertDialogBuilder
.setMessage("GPS is disabled in your device. Enable it?")
.setCancelable(false)
.setPositiveButton("Enable GPS",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
/** Here it's leading to GPS setting options*/
Intent callGPSSettingIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(callGPSSettingIntent);
}
});
alertDialogBuilder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}
}
以上代码将引导用户进入 gps 设置选项。但我在许多应用程序(最近的应用程序)中看到,确认后 gps 设置将自动启用为高精度。
我的问题是我需要在用户确认(对话框“是”)后将 GPS 设置启用为省电模式(或任何其他模式),而无需进入 GPS 设置。
MinSDK:9
TargetSDK:23
BuildToolVer:23.0.1
问候。
【问题讨论】:
-
供参考,可能会有所帮助 - stackoverflow.com/questions/28759454/…