【发布时间】:2014-09-10 07:47:20
【问题描述】:
我正在开发一个包含谷歌地图的项目。当活动加载时,我想检查 GPS 是否启用。所以我使用以下代码重定向到包含设置的页面。
if(!manager.isProviderEnabled( LocationManager.GPS_PROVIDER ))
{
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("GPS is disabled in your device. Would you like to enable it?")
.setCancelable(false)
.setPositiveButton("Goto Settings Page To Enable GPS",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
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然后开始活动
-
不询问用户就启用是不谨慎的