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.     }  
     
     
  • 相关阅读:
    PAT 乙级 1041 考试座位号(15) C++版
    四、Shell输入、输出功能和字符颜色设置
    三、Shell变量类型和运算符
    Shell文件权限和脚本执行
    Spark Standalone
    Loadrunner安装
    kali 2.0源更新
    xmanager远程桌面连接Linux
    Linux--文件查找命令
    Linux下MySQL忘记密码
  • 原文地址:https://www.cnblogs.com/xgjblog/p/6212611.html
Copyright © 2011-2022 走看看