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.     }  
     
     
  • 相关阅读:
    软件工程课程作业(四)--返回一个整数数组中最大子数组的和
    构建之法阅读笔记02
    第三周学习进度
    Delphi 之 编辑框控件(TEdit)
    Delphi 之 标签组件(TLabel组件)
    Delphi 之 第九课 Windows编程
    Delphi 之 第八课 动态数组
    VB API 之 第六课 字体应用三
    VB API 之 第五课 字体之其他函数介绍
    Delphi 之 第七课 字符串操作
  • 原文地址:https://www.cnblogs.com/xgjblog/p/6212611.html
Copyright © 2011-2022 走看看