zoukankan      html  css  js  c++  java
  • 安卓跳转到GPS设置界面

     
     
    1.     /** 
    2.      * 监听GPS 
    3.      */  
    4.     private void initGPS() {  
    5.         LocationManager locationManager = (LocationManager) this  
    6.                 .getSystemService(Context.LOCATION_SERVICE);  
    7.         // 判断GPS模块是否开启,如果没有则开启  
    8.         if (!locationManager  
    9.                 .isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {  
    10.             Toast.makeText(TrainDetailsActivity.this, "请打开GPS",  
    11.                     Toast.LENGTH_SHORT).show();  
    12.             AlertDialog.Builder dialog = new AlertDialog.Builder(this);  
    13.             dialog.setMessage("请打开GPS");  
    14.             dialog.setPositiveButton("确定",  
    15.                     new android.content.DialogInterface.OnClickListener() {  
    16.   
    17.                         @Override  
    18.                         public void onClick(DialogInterface arg0, int arg1) {  
    19.   
    20.                             // 转到手机设置界面,用户设置GPS  
    21.                             Intent intent = new Intent(  
    22.                                     Settings.ACTION_LOCATION_SOURCE_SETTINGS);  
    23.                             startActivityForResult(intent, 0); // 设置完成后返回到原来的界面  
    24.   
    25.                         }  
    26.                     });  
    27.             dialog.setNeutralButton("取消", new android.content.DialogInterface.OnClickListener() {  
    28.                   
    29.                 @Override  
    30.                 public void onClick(DialogInterface arg0, int arg1) {  
    31.                     arg0.dismiss();  
    32.                 }  
    33.             } );  
    34.             dialog.show();  
    35.         } else {  
    36.             // 弹出Toast  
    37. //          Toast.makeText(TrainDetailsActivity.this, "GPS is ready",  
    38. //                  Toast.LENGTH_LONG).show();  
    39. //          // 弹出对话框  
    40. //          new AlertDialog.Builder(this).setMessage("GPS is ready")  
    41. //                  .setPositiveButton("OK", null).show();  
    42.         }  
    43.     }  
     
     
  • 相关阅读:
    Java++:常用工具|性能监测|服务监控
    Vue++:Vuecli4.x 的配置文件配置方法
    Vue++: gyp ERR! find Python
    Node++:Windows 环境搭建 Vue 开发环境
    linux++:free h 详解
    踩坑纪:windows 系统下,nodejs版本管理器无法使用n来管理
    Node++:NodeJs 版本管理工具(n | nvm)n教程
    Vue++:Error: 'XXX' is defined but never used (nounusedvars)报错的解决方案
    [MOSS]关闭弹出窗口
    安装 64 位版本的 Office 2010 后,无法查看数据表视图中的列表
  • 原文地址:https://www.cnblogs.com/xgjblog/p/6212611.html
Copyright © 2011-2022 走看看