Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android.os.FileUriExposedException on installRemoteApp() #101

Closed
fauno opened this issue Sep 26, 2019 · 3 comments
Closed

android.os.FileUriExposedException on installRemoteApp() #101

fauno opened this issue Sep 26, 2019 · 3 comments

Comments

@fauno
Copy link

fauno commented Sep 26, 2019

Hi, I can't seem to use this code to install a downloaded app:

SendIntentAndroid
  .installRemoteApp('http://10.4.23.68:8080/app-release.apk', 'app.apk')
  .then((installWasStarted) => console.log(installWasStarted));

Throws this:

W System.err: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.app/files/app.apk exposed beyond app through Intent.getData()
W System.err:    at android.os.StrictMode.onFileUriExposed(StrictMode.java:1796)
W System.err:    at android.net.Uri.checkFileUriExposed(Uri.java:2354)
W System.err:    at android.content.Intent.prepareToLeaveProcess(Intent.java:8981)
W System.err:    at android.content.Intent.prepareToLeaveProcess(Intent.java:8942)
W System.err:    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1519)
W System.err:    at android.app.ContextImpl.startActivity(ContextImpl.java:791)
W System.err:    at android.app.ContextImpl.startActivity(ContextImpl.java:768)
W System.err:    at android.content.ContextWrapper.startActivity(ContextWrapper.java:356)
W System.err:    at android.content.ContextWrapper.startActivity(ContextWrapper.java:356)
W System.err:    at com.burnweb.rnsendintent.RNSendIntentModule$3.onResponse(RNSendIntentModule.java:450)
W System.err:    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
W System.err:    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
W System.err:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W System.err:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W System.err:    at java.lang.Thread.run(Thread.java:761)
I ReactNativeJS: false

Both from master and 1.0.30 using RN 0.59, the target SDK is 28. The only changes I've made to the code are from PR #99. Though it's no clear what should happen, does the apk installer open and offers the user to install the apk? I've checked #78, and added the permission recommended here https://stackoverflow.com/questions/45726654/install-apk-programmatically-in-android-8-api-26

@fauno
Copy link
Author

fauno commented Sep 26, 2019

Made it work with this patch, should I make a PR?

--- node_modules/react-native-send-intent/android/src/main/java/com/burnweb/rnsendintent/RNSendIntentModule.java.orig	2019-09-26 16:15:51.284106362 -0300
+++ node_modules/react-native-send-intent/android/src/main/java/com/burnweb/rnsendintent/RNSendIntentModule.java	2019-09-26 16:15:55.907579564 -0300
@@ -426,8 +443,13 @@
           try (final ResponseBody body = response.body()) {
             saveFile(body);
 
+            Uri uri = Uri.fromFile(file);
+            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
+              uri = FileProvider.getUriForFile(reactContext, reactContext.getPackageName() + ".fileprovider", file);
+            }
+
             final Intent intent = new Intent(Intent.ACTION_VIEW)
-                                  .setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
+                                  .setDataAndType(uri, "application/vnd.android.package-archive");
             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
 
             reactContext.startActivity(intent);

@lucasferreira
Copy link
Owner

Hi @fauno

The PR #99 it's about AndroidX + RN 0.60+ support. Do you think that your problem it's related to this scenario?

By the way if you could make some PR with your improvements that will be great ;)

fauno added a commit to fauno/react-native-send-intent that referenced this issue Sep 26, 2019
@fauno
Copy link
Author

fauno commented Sep 26, 2019

The PR #99 it's about AndroidX + RN 0.60+ support. Do you think that your problem it's related to this scenario?

No, I was just giving context :)

By the way if you could make some PR with your improvements that will be great ;)

Done! #102

lucasferreira added a commit that referenced this issue Sep 30, 2019
Uses content:// uris on newest APIs, closes #101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants