Skip to content

Commit 1c47e15

Browse files
authored
fix(android): Avoid SecurityError on Android 10 file share (#3655)
1 parent 1382c9f commit 1c47e15

File tree

1 file changed

+5
-0
lines changed
  • android/capacitor/src/main/java/com/getcapacitor/plugin

1 file changed

+5
-0
lines changed

android/capacitor/src/main/java/com/getcapacitor/plugin/Share.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Intent;
44
import android.net.Uri;
5+
import android.os.Build;
56
import android.webkit.MimeTypeMap;
67

78
import androidx.core.content.FileProvider;
@@ -50,6 +51,10 @@ public void share(PluginCall call) {
5051
intent.setType(type);
5152
Uri fileUrl = FileProvider.getUriForFile(getActivity(), getContext().getPackageName() + ".fileprovider", new File(Uri.parse(url).getPath()));
5253
intent.putExtra(Intent.EXTRA_STREAM, fileUrl);
54+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
55+
intent.setData(fileUrl);
56+
}
57+
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
5358
}
5459

5560
if (title != null) {

0 commit comments

Comments
 (0)