最近在做旅游项目,需要用到地图的定位导航,为了提高定位的精确度,在不打开GPS和打开GPS时,定位的偏差较大,

以下是在未打开GPS时弹出对话框提示用户设置GPS的相关代码:

/** * 判断GPS是否开启 */private void initGPS() {    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);    //判断GPS是否开启,没有开启,则开启    if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){        openGPSDialog();    }}
/** * 打开GPS对话框 */private void openGPSDialog() {    AlertDialog.Builder builder = new AlertDialog.Builder(this);    builder.setTitle("请打开GPS连接")            .setIcon(R.mipmap.ico_gps)            .setMessage("为了提高定位的准确度,更好的为您服务,请打开GPS")            .setPositiveButton("设置", new DialogInterface.OnClickListener() {                @Override                public void onClick(DialogInterface dialogInterface, int i) {                    //跳转到手机打开GPS页面                    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);                    //设置完成后返回原来的界面                    startActivityForResult(intent,0);                }            })             .setNeutralButton("取消", new DialogInterface.OnClickListener() {                @Override                public void onClick(DialogInterface dialogInterface, int i) {                dialogInterface.dismiss();                }            }).show();}
效果如下所示:

【Android】- Android判断GPS定位是否打开弹出对话框_第1张图片

更多相关文章

  1. Android 2.3禁止系统弹出应用程序强制退出对话框
  2. Android中自定义对话框(Dialog)
  3. Android常用控件--TimePickerDialog(时间选择对话框)
  4. Android 对话框大合集
  5. android在Service中弹出Dialog对话框,即全局性对话框
  6. Android中的对话框的使用技巧
  7. Android 第七天重置版_样式主题国际化动画对话框
  8. Android AlertDialog 对话框 ProgressDialog

随机推荐

  1. android sign签名
  2. 疯狂java讲义笔记 2.3.7
  3. Android(安卓)NDK c创建新的线程
  4. 使用Android Studio出现的一些问题解决策
  5. Android判断后台服务(Service)是否运行
  6. Android(安卓)Studio的几个Error与解决方
  7. android 游戏开发过程中让图片自适应
  8. android上文本框输入限制最大字节数
  9. android AlertDialog或toast显示错误 Una
  10. android asyncTask的使用