Android 9.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);
        }

    }

涉及的权限以及动态权限





 

你可能感兴趣的:(Android 9.0 更新要点)