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

Android 我向用户显示了启用gps设置的提示,但如何检查用户在其手机上是否真正启用了gps位置?,android,Android,我向用户显示了启用gps设置的提示,但如何检查用户在其手机上是否真正启用了gps位置 private static void showGPSDisabledAlertToUser() { // TODO Auto-generated method stub AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ChatSDK.getSDKInstance().activity);

我向用户显示了启用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();
    }
}
@用户3152953

你可以写这个来核对

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

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

保留一个布尔值的可能重复项,最初设置为false,并在发送意图时将其更改为true。如果为真,请在Resume上签入检查gps连接,并将布尔值更改为假。@user3152953检查我的答案,如果你想要其他东西给我详细信息,你可以检查这个,如果你想要其他东西给我详细信息这是我已经在使用的,我在非活动类中使用了一个问题。然后在调用非活动类时传递上下文
 if (!((LocationManager) context.getSystemService(Context.LOCATION_SERVICE))
    .isProviderEnabled(LocationManager.GPS_PROVIDER)) {
 //prompt user to enable gps
 }else{
 //gps is enabled
 }