Android-9.0更新內容要點

一、位置信息 開關及判定

Android 9.0系統(tǒng)獲取定位需要位置信息權限,看來谷歌對于隱私權限的進一步收緊,

/**
     * 打開位置信息設定開關
     *
     * @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);
        }

    }

涉及的權限以及動態(tài)權限

<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" />

二、為保證用戶數(shù)據(jù)和設備的安全

1). 簡介
Google表示,為保證用戶數(shù)據(jù)和設備的安全,針對下一代 Android 系統(tǒng)(Android P) 的應用程序,將要求默認使用加密連接,這意味著 Android P 將禁止 App 使用所有未加密的連接,因此運行 Android P 系統(tǒng)的安卓設備無論是接收或者發(fā)送流量,未來都不能明碼傳輸,需要使用下一代(Transport Layer Security)傳輸層安全協(xié)議,而 Android Nougat 和 Oreo 則不受影響。
2). 解決方案

APP改用https請求
targetSdkVersion 降到27以下
在 res 下新增一個 xml 目錄,然后創(chuàng)建一個名為:network_security_config.xml 文件(名字自定) ,內容如下,大概意思就是允許開啟http請求

3). 配置(簡述第三種方案)

在res下新建xml文件夾,創(chuàng)建名為network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
在AndroidManifest.xml文件的application節(jié)點中配置

<application
...
android:networkSecurityConfig="@xml/network_security_config"
...
/>

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容