pwlin / cordova-plugin-file-opener2

A File Opener Plugin for Cordova
MIT License
314 stars 584 forks source link

Switching out of Android app closes file - why? #270

Open SteveW117 opened 4 years ago

SteveW117 commented 4 years ago

Currently testing version 2.0.19 with Cordova 6.5.0.

I can open PDFs and other files in Android and iOS OK. However, in Android if I switch away from the app (e.g. to the Home screen or recent apps) and switch back to my app, the file has closed. There seem to be no errors logged, but it means the user must then open the file again (which works).

I have also noticed in Android that if I open a PDF it seems to open within the app - but in the recent apps screen I can see 2 tabs, one for my app and one for the PDF. If I click my app the above behaviour occurs - if I click the PDF it simply disappears and dumps me back to the Home screen!

Are these behaviours expected? I have looked through all the issues and can't see anyone else reporting them... In iOS everything works as expected, the file opens within the app and I can switch out and back into it with no problems.

Any help or advice appreciated!

pawelzwronek commented 4 years ago

Try replace line in file FileOpener2.java function _open from cordova.getActivity().startActivity(intent); to cordova.getActivity().getApplicationContext().startActivity(intent); It helped me to run uninstall and open older version of apk to do self downgrade.

Or add Intent.FLAG_ACTIVITY_NEW_TASK in intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY);

SteveW117 commented 4 years ago

Thanks - did you experience the Android behaviour I described? It does not seem to have been widely reported. I wondered if it was because my Cordova and plugin versions were out-of-date... I am not working on the project right now but will log your suggestions for next time I am on it, Thanks again!

anypoint-aus commented 3 years ago

I know this is old thread, but I also have same issue with latest plugin and cannot find a solution. I tried the changes above did not help. Some investigation I did seems to suggest maybe services are required to keep the activity running after it goes to the background?

pawelzwronek commented 3 years ago

For me crucial was this commit 3eb2bc73806d658260aa748dbb83f23def7fb830 Make sure flag Intent.FLAG_ACTIVITY_NO_HISTORY is removed

anypoint-aus commented 3 years ago

Thanks @pawelzwronek seems to be working nicely now!

Sampath-Lokuge commented 3 years ago

@pawelzwronek This is not working again with 3.0.3. It has your fix too. Any clue?

Error

message: "Activity not found: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://com.reno.fileOpener2.provider/files/csvExport.csv typ=text/csv flg=0x3 }"
status: 9
pawelzwronek commented 3 years ago

Is it working with any older version?

Sampath-Lokuge commented 3 years ago

@pawelzwronek No. I started from this 2.2.1. After that this 3.0.1 That version showed this error Fixed: Failed to find configured root that contains "/data/data/{app_name_redacted}/files/" So then I used this 3.0.3.

pawelzwronek commented 3 years ago

So why did you write "not working AGAIN", like it worked for you in the past? This is some new bug on you side or the plugin, right?

Sampath-Lokuge commented 3 years ago

@pawelzwronek I have given that feedback due to this comment https://github.com/pwlin/cordova-plugin-file-opener2/issues/270#issuecomment-772941099 i.e. I hope it worked for him and you on Feb. But now it is not working. I have used 2.2.1 for a very long time period and it worked. But due to the new Android 10 support where I have upgraded my app to API level 29. After that this functionality is not working anymore.

pawelzwronek commented 3 years ago

It looks like new Android 10 is the issue. Can you describe the use case, when you get the error?