Android 7.0以上 權(quán)限新特性

一 、FileProvider共享文件

在scr/res下新建一個文件夾命名為'xml'
xml文件夾下創(chuàng)建一個xml,名稱隨意


示例截圖.png

1. 在update_cache_path.xml文件里面加入以下對應(yīng)內(nèi)部存儲的根目錄

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
   <!--1、對應(yīng)內(nèi)部內(nèi)存卡根目錄:Context.getFileDir()-->
   <files-path
       name="int_root"
       path="." />
   <!--2、對應(yīng)應(yīng)用默認(rèn)緩存根目錄:Context.getCacheDir()-->
   <cache-path
       name="app_cache"
       path="." />
   <!--3、對應(yīng)外部內(nèi)存卡根目錄:Environment.getExternalStorageDirectory()-->
   <external-path
       name="storage"
       path="." />
   <!--4、對應(yīng)外部內(nèi)存卡根目錄下的APP公共目錄:Context.getExternalFileDir(String)-->
   <external-files-path
       name="ext_pub"
       path="." />
   <!--5、對應(yīng)外部內(nèi)存卡根目錄下的APP緩存目錄:Context.getExternalCacheDir()-->
   <external-cache-path
       name="ext_cache"
       path="." />
   <root-path
       name="root_path"
       path="." />
</paths>

2.在AndroidManifest.xml中引入update_cache_path.xml即可

<application>
      <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.UpdateFileProvider"
            android:exported="false"
            android:grantUriPermissions="true"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_path"
                tools:replace="android:resource" />
        </provider>
</application>

一 、網(wǎng)絡(luò)權(quán)限

Android9.0之后Google就限制了http的訪問權(quán)限,因為http的訪問形式是不安全的,只能以https開頭請求訪問網(wǎng)絡(luò)。那么針對這種限制,Google也給出了處理方式。

在scr/res下新建一個文件夾命名為'xml'
xml文件夾下創(chuàng)建一個xml,名稱隨意


示例截圖.png

1.在network_security_config.xml中寫入網(wǎng)絡(luò)配置

<?xml version="1.0" encoding="utf-8"?>
<!--Android 9.0 http網(wǎng)絡(luò)配置-->
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

2.在AndroidManifest.xml中引入network_security_config.xml

 <application
        android:name=".App"
        android:icon="@mipmap/app_icon"
        android:label="@string/app_name"
        android:networkSecurityConfig="@xml/network_security_config"
        android:theme="@style/AppTheme"
        tools:replace="android:icon, android:theme,android:allowBackup,android:label"
        tools:targetApi="n"
        tools:ignore="GoogleAppIndexingWarning">
 </application>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容