Committed by
David PHAM-VAN
fixed permission denial while sharing file with fileprovider
Showing
1 changed file
with
12 additions
and
13 deletions
@@ -19,32 +19,19 @@ package net.nfet.flutter.printing; | @@ -19,32 +19,19 @@ package net.nfet.flutter.printing; | ||
19 | import android.content.Context; | 19 | import android.content.Context; |
20 | import android.content.Intent; | 20 | import android.content.Intent; |
21 | import android.content.res.Configuration; | 21 | import android.content.res.Configuration; |
22 | -import android.graphics.Bitmap; | ||
23 | -import android.graphics.Matrix; | ||
24 | -import android.graphics.pdf.PdfRenderer; | ||
25 | import android.net.Uri; | 22 | import android.net.Uri; |
26 | -import android.os.Build; | ||
27 | import android.os.Bundle; | 23 | import android.os.Bundle; |
28 | import android.os.CancellationSignal; | 24 | import android.os.CancellationSignal; |
29 | -import android.os.Handler; | ||
30 | -import android.os.Looper; | ||
31 | import android.os.ParcelFileDescriptor; | 25 | import android.os.ParcelFileDescriptor; |
32 | import android.print.PageRange; | 26 | import android.print.PageRange; |
33 | import android.print.PdfConvert; | 27 | import android.print.PdfConvert; |
34 | import android.print.PrintAttributes; | 28 | import android.print.PrintAttributes; |
35 | -import android.print.PrintDocumentAdapter; | ||
36 | -import android.print.PrintDocumentInfo; | ||
37 | import android.print.PrintJob; | 29 | import android.print.PrintJob; |
38 | -import android.print.PrintJobInfo; | ||
39 | import android.print.PrintManager; | 30 | import android.print.PrintManager; |
40 | -import android.util.Log; | ||
41 | import android.webkit.WebView; | 31 | import android.webkit.WebView; |
42 | import android.webkit.WebViewClient; | 32 | import android.webkit.WebViewClient; |
43 | - | ||
44 | import androidx.annotation.NonNull; | 33 | import androidx.annotation.NonNull; |
45 | -import androidx.annotation.RequiresApi; | ||
46 | import androidx.core.content.FileProvider; | 34 | import androidx.core.content.FileProvider; |
47 | - | ||
48 | import java.io.File; | 35 | import java.io.File; |
49 | import java.io.FileInputStream; | 36 | import java.io.FileInputStream; |
50 | import java.io.FileOutputStream; | 37 | import java.io.FileOutputStream; |
@@ -52,6 +39,12 @@ import java.io.IOException; | @@ -52,6 +39,12 @@ import java.io.IOException; | ||
52 | import java.io.OutputStream; | 39 | import java.io.OutputStream; |
53 | import java.nio.ByteBuffer; | 40 | import java.nio.ByteBuffer; |
54 | import java.util.HashMap; | 41 | import java.util.HashMap; |
42 | +import android.content.pm.PackageManager; | ||
43 | +import android.content.pm.ProviderInfo; | ||
44 | +import android.content.pm.ResolveInfo; | ||
45 | +import java.util.List; | ||
46 | + | ||
47 | + | ||
55 | 48 | ||
56 | /** | 49 | /** |
57 | * PrintJob | 50 | * PrintJob |
@@ -223,6 +216,12 @@ public class PrintingJob extends PrintDocumentAdapter { | @@ -223,6 +216,12 @@ public class PrintingJob extends PrintDocumentAdapter { | ||
223 | shareIntent.putExtra(Intent.EXTRA_STREAM, apkURI); | 216 | shareIntent.putExtra(Intent.EXTRA_STREAM, apkURI); |
224 | shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 217 | shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
225 | Intent chooserIntent = Intent.createChooser(shareIntent, null); | 218 | Intent chooserIntent = Intent.createChooser(shareIntent, null); |
219 | + List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(chooserIntent, PackageManager.MATCH_DEFAULT_ONLY); | ||
220 | + | ||
221 | + for (ResolveInfo resolveInfo : resInfoList) { | ||
222 | + String packageName = resolveInfo.activityInfo.packageName; | ||
223 | + context.grantUriPermission(packageName, apkURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||
224 | + } | ||
226 | context.startActivity(chooserIntent); | 225 | context.startActivity(chooserIntent); |
227 | shareFile.deleteOnExit(); | 226 | shareFile.deleteOnExit(); |
228 | } catch (IOException e) { | 227 | } catch (IOException e) { |
-
Please register or login to post a comment