美文网首页Android适配经验
Android 9.0 更新要点

Android 9.0 更新要点

作者: 唔笛plk | 来源:发表于2018-12-03 09:56 被阅读0次

    一、位置信息 开关及判定

    Android 9.0系统获取定位需要位置信息权限,看来谷歌对于隐私权限的进一步收紧,

    /**
         * 打开位置信息设定开关
         *
         * @param context
         */
        public static void openLocation(Context context) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            context.startActivity(intent);
        }
    **
         * 判断位置信息界面是否打开,
         *
         * @param context
         */
        public static boolean isOpenLocation(Context context) {
            int locationMode = 0;
            String locationProviders;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                try {
                    locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
                } catch (Settings.SettingNotFoundException e) {
                    e.printStackTrace();
                }
                return locationMode != Settings.Secure.LOCATION_MODE_OFF;
            } else {
                locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
                return !TextUtils.isEmpty(locationProviders);
            }
    
        }
    

    涉及的权限以及动态权限

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    

    相关文章

      网友评论

        本文标题:Android 9.0 更新要点

        本文链接:https://www.haomeiwen.com/subject/oovgqqtx.html