Skip to content

Unable to create compressed file in Android Oreo (8.0) #42

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

Open
nkurapati opened this issue Jun 4, 2018 · 13 comments
Open

Unable to create compressed file in Android Oreo (8.0) #42

nkurapati opened this issue Jun 4, 2018 · 13 comments

Comments

@nkurapati
Copy link

nkurapati commented Jun 4, 2018

Hi,

This plugin is working as a charm but suddenly it stopped working, we found that its working well till till Android 7.0 but not in Android Oreo 8.0.

We are getting "Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference".

I see that its not able to create folder and compressed file in given folder.

Please let us know if you found any work around for Android 8.0.

thank you

@nkurapati
Copy link
Author

I see a fix here, but its still not working for me. Please update if you see fix in this.

https://stackoverflow.com/questions/46489706/android-oreo-api-26-create-dir-in-external-storage

@IgneButene
Copy link

I have the same issue on my Samsung S9 Oreo 8.0.0

@JoschkaSchulz
Copy link
Owner

hrm... I will try to find out more... I tried it on a android 9 device and it works without problems... maybe the problems are just appear in 8?

@nkurapati
Copy link
Author

May be.. I don't have android 9 so didn't checked.

@JoschkaSchulz
Copy link
Owner

I will check different android versions later the day.

@nkurapati
Copy link
Author

nkurapati commented Jun 13, 2018 via email

@crawft
Copy link

crawft commented Jun 13, 2018

Same here, 8.1.

I've never worked with native Android code but it looks like folder.mkdir(); must be failing, then you don't check the result of saveFile (which is null after mkdir fails).

Something to do with permissions?

@nkurapati
Copy link
Author

@JoschkaSchulz Any updates?

@crawft Permissions are looking good.

@nkurapati
Copy link
Author

nkurapati commented Jun 18, 2018

@JoschkaSchulz

I have debugged the code and its failing to create folder at line no#115: success = folder.mkdir(). So saveFile function is returning null and scaledFile.toString() is failing at line no#61.

I have tested line no#110 as follows, but still same error.

  • folder = new File(Environment.getExternalStorageDirectory() + "/" + folderName);
  • folder = new File(Environment.getExternalStorageDirectory(), folderName);

I have following permissions:
uses-sdk android:minSdkVersion="16"
uses-permission android:name="android.permission.INTERNET"
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
uses-feature android:name="android.hardware.location.gps"
uses-permission android:name="android.permission.RECORD_AUDIO"

preference name="AndroidPersistentFileLocation" value="Internal"
preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,assets,root"

Please let me know if I am missing anything.

@crawft
Copy link

crawft commented Jun 18, 2018

I worked around this by changing the code around line 129 as follows, this creates the resized image in a private folder so may not work if you want the image elsewhere (though maybe you could just copy it after or something).

Context context = this.cordova.getActivity().getApplicationContext();
folder = context.getDir(folderName, context.MODE_PRIVATE);

@JoschkaSchulz
Copy link
Owner

@crawft would you be so kind to create a pull request? then we could fix that for everyone :)

@jayordway jayordway mentioned this issue Jul 31, 2018
@jayordway
Copy link
Contributor

I used the method that @crawft had given and created a PR for it.

JoschkaSchulz pushed a commit that referenced this issue Jul 31, 2018
Fix for #42 - Unable to create compressed file in Android Oreo (8.0)
@shide1989
Copy link

any news on this Topic ? the branch was merged in 2018 and this issue isn't closed.
i'm still having the issue on Android 29

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

6 participants