Explorar o código

Fixed API 24 FileProvider error

Bram van de Kerkhof %!s(int64=8) %!d(string=hai) anos
pai
achega
7d3d0999f3

+ 10 - 0
app/src/main/AndroidManifest.xml

@@ -54,6 +54,16 @@
             android:theme="@style/FilePickerTheme">
         </activity>
 
+        <provider
+            android:name="android.support.v4.content.FileProvider"
+            android:authorities="eu.kanade.tachiyomi.provider"
+            android:exported="false"
+            android:grantUriPermissions="true">
+            <meta-data
+                android:name="android.support.FILE_PROVIDER_PATHS"
+                android:resource="@xml/provider_paths"/>
+        </provider>
+
         <service android:name=".data.library.LibraryUpdateService"
             android:exported="false"/>
 

+ 4 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/reader/notification/ImageNotificationReceiver.kt

@@ -5,6 +5,7 @@ import android.content.BroadcastReceiver
 import android.content.Context
 import android.content.Intent
 import android.net.Uri
+import android.support.v4.content.FileProvider
 import eu.kanade.tachiyomi.R
 import eu.kanade.tachiyomi.util.notificationManager
 import java.io.File
@@ -61,8 +62,9 @@ class ImageNotificationReceiver : BroadcastReceiver() {
     private fun showImage(context: Context, path: String) {
         val intent = Intent().apply {
             action = Intent.ACTION_VIEW
-            flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
-            setDataAndType(Uri.parse("file://" + path), "image/*")
+            flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
+            val uri = FileProvider.getUriForFile(context,"eu.kanade.tachiyomi.provider",File(path))
+            setDataAndType(uri, "image/*")
         }
         context.startActivity(intent)
     }

+ 4 - 0
app/src/main/res/xml/provider_paths.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<paths>
+    <external-path name="pictures" path="Pictures" />
+</paths>