cordova-plugin-file-opener2 icon indicating copy to clipboard operation
cordova-plugin-file-opener2 copied to clipboard

Switching out of Android app closes file - why?

Open SteveW117 opened this issue 5 years ago • 11 comments

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!

SteveW117 avatar Sep 17 '19 10:09 SteveW117

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);

pawelzwronek avatar Oct 06 '19 18:10 pawelzwronek

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!

SteveW117 avatar Oct 07 '19 08:10 SteveW117

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?

anypoint-aus avatar Feb 03 '21 04:02 anypoint-aus

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

pawelzwronek avatar Feb 03 '21 11:02 pawelzwronek

Thanks @pawelzwronek seems to be working nicely now!

anypoint-aus avatar Feb 04 '21 00:02 anypoint-aus

@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

Sampath-Lokuge avatar Mar 15 '21 20:03 Sampath-Lokuge

Is it working with any older version?

pawelzwronek avatar Mar 15 '21 21:03 pawelzwronek

@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.

Sampath-Lokuge avatar Mar 15 '21 21:03 Sampath-Lokuge

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?

pawelzwronek avatar Mar 16 '21 14:03 pawelzwronek

@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.

Sampath-Lokuge avatar Mar 16 '21 15:03 Sampath-Lokuge

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

pawelzwronek avatar Mar 16 '21 15:03 pawelzwronek