瀏覽代碼

修复FileProvider冲突

ketchup 3 年之前
父節點
當前提交
8ee1e12438

+ 3 - 3
net/src/main/AndroidManifest.xml

@@ -20,13 +20,13 @@
             android:exported="false"
             android:multiprocess="true" />
         <provider
-            android:name="androidx.core.content.FileProvider"
-            android:authorities="${applicationId}.fileProvider"
+            android:name=".component.NetFileProvider"
+            android:authorities="${applicationId}.drake.netFileProvider"
             android:exported="false"
             android:grantUriPermissions="true">
             <meta-data
                 android:name="android.support.FILE_PROVIDER_PATHS"
-                android:resource="@xml/file_paths" />
+                android:resource="@xml/net_file_paths" />
         </provider>
     </application>
 

+ 8 - 0
net/src/main/java/com/drake/net/component/NetFileProvider.kt

@@ -0,0 +1,8 @@
+package com.drake.net.component
+
+import androidx.core.content.FileProvider
+
+/**
+ * 用于临时获取文件读写权限
+ */
+class NetFileProvider : FileProvider()

+ 1 - 1
net/src/main/java/com/drake/net/utils/FileUtils.kt

@@ -87,7 +87,7 @@ fun File.install() {
     val uri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
         FileProvider.getUriForFile(
             context,
-            "${context.packageName}.fileProvider",
+            "${context.packageName}.drake.netFileProvider",
             this
         )
     } else {

+ 0 - 0
net/src/main/res/xml/file_paths.xml → net/src/main/res/xml/net_file_paths.xml


+ 3 - 1
sample/src/main/java/com/drake/net/sample/ui/fragment/DownloadFileFragment.kt

@@ -16,6 +16,7 @@
 
 package com.drake.net.sample.ui.fragment
 
+import android.annotation.SuppressLint
 import android.view.Menu
 import android.view.MenuInflater
 import android.view.MenuItem
@@ -35,11 +36,12 @@ class DownloadFileFragment :
 
     private lateinit var downloadScope: NetCoroutineScope
 
+    @SuppressLint("SetTextI18n")
     override fun initView() {
         setHasOptionsMenu(true)
         downloadScope = scopeNetLife {
             val file =
-                Get<File>("https://download.sublimetext.com/Sublime%20Text%20Build%203211.dmg") {
+                Get<File>("https://dl.coolapk.com/down?pn=com.coolapk.market&id=NDU5OQ&h=46bb9d98&from=from-web") {
                     setDownloadFileName("net.apk")
                     setDownloadDir(requireContext().filesDir)
                     setDownloadMd5Verify()