【问题标题】: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 位置?
【发布时间】:2014-04-26 21:23:26
【问题描述】:

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

【问题讨论】:

  • 保留一个布尔值并最初设置为 false 并在发送意图时将其更改为 true。并检查 onResume 是否为真检查那里的 gps 连接并将布尔值更改为假。
  • @user3152953 查看我的答案,如果您想了解其他信息,请给我详细信息,

标签: android


【解决方案1】:
 if (!((LocationManager) context.getSystemService(Context.LOCATION_SERVICE))
    .isProviderEnabled(LocationManager.GPS_PROVIDER)) {
 //prompt user to enable gps
 }else{
 //gps is enabled
 }

【讨论】:

  • 这是我已经使用的,我在非活动类中使用的有问题。
  • 然后在调用非活动类时传递上下文
【解决方案2】:

@user3152953

你可以写这个来检查

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

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

【讨论】:

  • 你可以检查这个,如果你想要别的东西给我详细信息
猜你喜欢
  • 2016-03-05
  • 2011-08-27
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 2020-09-26
  • 2014-09-10
相关资源
最近更新 更多