zoukankan      html  css  js  c++  java
  • 判断GPS是否开启&转到设置GPS界面

    /**
         * 判断GPS是否开启,GPS或者AGPS开启一个就认为是开启的
         * @param context
         * @return true 表示开启
         */
        public static final boolean isGPSOPen(final Context context) {
            LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
            // 通过GPS卫星定位,定位级别可以精确到街(通过24颗卫星定位,在室外和空旷的地方定位准确、速度快)
            boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
            // 通过WLAN或移动网络(3G/2G)确定的位置(也称作AGPS,辅助GPS定位。主要用于在室内或遮盖物(建筑群或茂密的深林等)密集的地方定位)
            boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
            if (gps || network) {
                return true;
            }
            return false;
        }
        /**
         * 转到设置GPS界面
         * @param context
         */
        public static final void gotoSetGPS(Context context) {
            Intent intent = new Intent();
            intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try{
                context.startActivity(intent);
            } catch(ActivityNotFoundException ex) {
                // The Android SDK doc says that the location settings activity
                // may not be found. In that case show the general settings.
                // General settings activity
                intent.setAction(Settings.ACTION_SETTINGS);
                context.startActivity(intent);
            }
        }
  • 相关阅读:
    npm 5.4.2 更新后就不能用了
    Node.js 被分叉出一个项目 — Ayo.js,肿么了
    页面缓存之Meta http-equiv属性详解
    Javascript 浮点计算问题分析与解决
    详解 Cookie 纪要(vue.cookie,jquery.cookie简化)
    Cookie 基本操作
    HTML5上传图片预览
    location.href跳转测试
    ios中iframe的scroll滚动事件替代方法
    JS数组API
  • 原文地址:https://www.cnblogs.com/genggeng/p/5356362.html
Copyright © 2011-2022 走看看