首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我向用户显示了启用gps设置的提示,但我如何检查用户是否真的在其手机上启用了gps位置?

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

Stack Overflow用户
提问于 2014-03-20 15:21:47
回答 2查看 3.2K关注 0票数 5

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

代码语言:javascript
复制
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();
    }
}
EN

回答 2

Stack Overflow用户

发布于 2014-03-20 15:27:51

代码语言:javascript
复制
 if (!((LocationManager) context.getSystemService(Context.LOCATION_SERVICE))
    .isProviderEnabled(LocationManager.GPS_PROVIDER)) {
 //prompt user to enable gps
 }else{
 //gps is enabled
 }
票数 4
EN

Stack Overflow用户

发布于 2014-03-20 15:25:05

@user3152953

你可以写下这段代码来检查

代码语言:javascript
复制
boolean isGPS ;
 isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);

 if(isGPS)
  {
     //gps is open already
  }
 else
 {
    //gps is close already
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22526078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档