Skip to content
New issue

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

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

Already on GitHub? # to your account

writeFile crashes #297

Closed
newuser44 opened this issue Mar 4, 2019 · 8 comments
Closed

writeFile crashes #297

newuser44 opened this issue Mar 4, 2019 · 8 comments

Comments

@newuser44
Copy link

Bug Report

Problem

On a Samsung S5 with Android 6.0.1 calling writeFile crashes somewhere.

What is expected to happen?

Save a file.

What does actually happen?

I have tried to debug it down into the maybe FileWriter.js and see it trying to write the file. But then the debugger stopped stepping through code. Something crashed and its not being caught.

Information

Not sure if the problem is the Samsung or Android 6.0. Build this onto a phone.
Would need to some type of blob that is getting saved as a PDF document.
Try to save the file.

Environment, Platform, Device

I only have the problem on a Samsung S5 running Android 6.0.1
This worked fine on
-- Pixel 2 (not sure the os 8 or 9)
-- Samsung S7 with android 8.
-- iphone 8 and 9.

Version information

Ionic 3.9
Uninstalled and reinstalled. (following the Ionic 3 steps)
"@ionic-native/file": "^4.20.0",
"cordova-plugin-file": "~6.0.1"

Checklist

  • [x ] I searched for existing GitHub issues
  • [x ] I updated all Cordova tooling to most recent version
  • [x ] I included all the necessary information above
@newuser44
Copy link
Author

newuser44 commented Mar 7, 2019

I have concluded it seems to be some problem with the write permissions. There is a note about Android 6.0 having that problem.
I can't figure out which should be the correct directory.
What is probably more annoying is we have different app with 90% the same code, doing the same thing in downloading a PDF file and saving it. It use file.dataDirectory.
What is so confusing is one app is able to access file.dataDirectory but a different app on the same phone has problems???
I even uninstalled android, tried to make sure all the plugins were the same. Still same result.
Can't seem to find anything else that would cause it.

@newuser44
Copy link
Author

newuser44 commented Mar 7, 2019

I accidentally removed android from the app that had this working. I added Android 6.3 back which is what it had before. Now it also doesn't work. Some android file must be part of the problem.

@newuser44
Copy link
Author

I think I give up.
I got my old app working. That seems to work find using just dataDirectory on Android 6.0.

The new app still has the same problem. I am even seeing a problem with the write access between builds. Decided to do more testing.

This was all testing on a Samsung S5 with Android 6.0.1
externalRootDirectory works but asks for permission
externalRootDirectory/Download/ also - worked but asks for permission

externalApplicationStorageDirectory --Did not work
externalDataDirectory; Did not work

applicationStorageDirectory It looks like writing the file was successful but reading the file got this -- Error
Failed to find configured root that contains /data/data//.pdf

So pushing files to externalRootDirectory was my only hope. Changed code that if Android was 6 or less us externalRootDirectory/Download/ if its anything else (ios or Android > 7) use dataDirectory.
I build again, and it stopped working. A pdf file is created but no data can be pushed to it. Same build worked find on a Samsung S3 with Android 4.4.

Remove the plugin and installed it again.
Go it to work on Android 6.0. It worked. Tried it on Pixel 2 it worked.
But on an HTC 10 with Android 7.0 it does not work. Seems like the same thing where it just can't push data to it.

I really don't know what else to do this this plugin.

@synnottd
Copy link

synnottd commented Mar 8, 2019

@newuser44 #237 might fix your issue. I also spent many, many hours on this.

@newuser44
Copy link
Author

    • Thanks
  1. How do I get this fix?
  2. Why isn't it merged into the code?

@synnottd
Copy link

synnottd commented Mar 8, 2019

It is merged but there hasn't been an npm release (no idea how Apache manages that).

Instructions: danielsogl/awesome-cordova-plugins#2067 (comment)

You can use this repo rather than the forked one either.

ionic cordova plugin rm cordova-plugin-file
ionic cordova plugin add https://github.com/apache/cordova-plugin-file.git

Pointing to git rather than an npm can be problematic, there is lots of ifs, buts, and maybes. I'd suggest googling around for the best solution for you.

@newuser44
Copy link
Author

So danielsogl/awesome-cordova-plugins#2067 (comment) changed the files directly and that seemed to work for Android 6.0.1.
This worked for Android 6.0.1 phone and 7.0 and either Android 8.

But now on Android 4.4 phone go to open the file I get an error about can't find the path.
I can't tell exactly which part. It does seem like writing the file is successful (Or it thinks it is). but when it goes to open the file it can't find the file.

I have tried dataDirectory that worked for all other phones (but I can't actually find this location on the phone). Just tried applicationStorageDirectory but that seems to be the same path on this older phone.
file:///data/data/appname/files/"

Not sure what else is left?

@breautek
Copy link
Contributor

I realise that this issue is old but I'l give some (modern) answers...

applicationStorageDirectory is a read only directory. This directory is your application install directory.

With Android's scoped storage, enforced in API 30 and later, externalRootDirectory is not a writable directory. However externalRootDirectory + "Download" (or one of the other predefined directories) is writable, assuming you choose a file that doesn't already exists. Creating custom directory structures is also forbidden in external storage, except for in your own application's external data folder.

I'm unable to reproduce any "crashes", just errors as I would expect via the error callbacks.

Hope this helps, if the issue persists with the current versions of the platform/plugin, then please create a new issue with updated information.

@breautek breautek closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants