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.     }  
     
     
  • 相关阅读:
    「日常训练」Single-use Stones (CFR476D2D)
    「日常训练」Greedy Arkady (CFR476D2C)
    「Haskell 学习」二 类型和函数(上)
    「学习记录」《数值分析》第二章计算实习题(Python语言)
    「日常训练」Alena And The Heater (CFR466D2D)
    Dubbo 消费者
    Dubbo 暴露服务
    Rpc
    git fail to push some refs....
    Spring Cloud (6)config 客户端配置 与GitHub通信
  • 原文地址:https://www.cnblogs.com/xgjblog/p/6212611.html
Copyright © 2011-2022 走看看