简体   繁体   English

我向用户显示了启用gps设置的提示,但是如何检查用户是否在手机上真正启用了gps位置?

[英]i showed prompt to user to enable gps settings,but how can i check user really enabled the gps location on his phone?

I showed prompt to user to enable gps settings,but how can I check user really enabled the gps location on his phone? 我向用户显示了启用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();
    }
}
 if (!((LocationManager) context.getSystemService(Context.LOCATION_SERVICE))
    .isProviderEnabled(LocationManager.GPS_PROVIDER)) {
 //prompt user to enable gps
 }else{
 //gps is enabled
 }

@user3152953 @ user3152953

you can write this to check 你可以写这个来检查

boolean isGPS ;
 isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);

 if(isGPS)
  {
     //gps is open already
  }
 else
 {
    //gps is close already
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM