一 瘾腰、FileProvider共享文件
在scr/res下新建一個文件夾命名為'xml'
xml文件夾下創(chuàng)建一個xml鹅髓,名稱隨意
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)用默認緩存根目錄: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娩嚼,名稱隨意
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>