我向用户显示了启用gps设置的提示,但我如何检查用户是否真的在其手机上启用了gps位置?
private static void showGPSDisabledAlertToUser() {
// TODO Auto-generated method stub
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ChatSDK.getSDKInstance().activity);
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);
ChatSDK.getSDKInstance().activity.startActivity(callGPSSettingIntent);
}
});
// alertDialogBuilder.setNegativeButton("Cancel",
// new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int id) {
// dialog.cancel();
// }
// });
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}
}发布于 2014-03-20 15:27:51
if (!((LocationManager) context.getSystemService(Context.LOCATION_SERVICE))
.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//prompt user to enable gps
}else{
//gps is enabled
}发布于 2014-03-20 15:25:05
@user3152953
你可以写下这段代码来检查
boolean isGPS ;
isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);
if(isGPS)
{
//gps is open already
}
else
{
//gps is close already
}https://stackoverflow.com/questions/22526078
复制相似问题