joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 770 forks source link

Add the FLAG_ACTIVITY_NEW_TASK flag. #317

Closed wakeless closed 4 years ago

wakeless commented 5 years ago

This is caused by an error on Android 9: 'Error: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?'

andresouza commented 5 years ago

It would be nice to have this one merged. Thank you!

acatalina commented 5 years ago

I need to fork this repo just for that reason but probably rather than enforce it for everyone it should be pass as a parameter instead?

squalvj commented 5 years ago

+1 please someone merge this PR, it works!

wakeless commented 5 years ago

FWIW this has been working in production for us for quite some time.

mouchegmouradian commented 5 years ago

Any chance someone merges this ? (and all the other 39 PRs) or give permissions to other people so they can do the merges.

AdeilsonSuperlogica commented 5 years ago

I solved this issue with a workaround. Just add this in your package.json postinstall:

"postinstall": "exec sed -i '' '122i\\\nintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);' node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java"

I used this PR to make changes. I hope it helps you.

ErickMaeda commented 5 years ago

Thanks @AdeilsonSuperlogica it solved my issue!

superRenanC commented 5 years ago

Solved for me @AdeilsonSuperlogica

ganesh98a commented 5 years ago

So basically this needs to be added to line 122-123 of file android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

if above step is not working to do the below step: overwrite the line 121 in android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  // line 121 
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);   // line 122 
pedrosobral commented 5 years ago

Just in case, you guys can also install the package directly from this branch.

yarn add git+https://github.com/Ferocia/rn-fetch-blob.git#android-9-open-file

Thanks, @wakeless!

walterholohan commented 4 years ago

@Traviskn do you think this PR will get merged anytime soon? Ive come across this issue when trying to open a PDF on Android using RNFetchBlob.android.actionViewIntent( targetPath, 'application/pdf' )

Maddumage commented 4 years ago

https://github.com/joltup/rn-fetch-blob/pull/317#issuecomment-496812470 This worked me well

Traviskn commented 4 years ago

Thank you for all the testing confirmation that this PR fixes the described issue, apologies for the delayed review

nobady90 commented 4 years ago

as already asked by @bova80 there are many who do not want or be able to update react-native to version 0.60 or higher... so is it possible to update to have a merge to solve this problem also in version 0.10.15? Thanks

LouisJS commented 4 years ago

Is this fix available in 0.10.15 ? Because i'm still facing it

V1adau commented 4 years ago

+1, still facing this issue in 0.10.15

iaminvictus1993 commented 4 years ago

mark Add the FLAG_ACTIVITY_NEW_TASK flag.