My Ionic plugin does not works on MarshMallow


#1

Hi to all,
I’ve done a custom Ionic plugin, who read and write a cripted file in the external storage file system on android device.
On android version < 6.0 (marshmallow) it works fine, but on Android 6.0.0 I have this error:

java.io.FileNotFoundException: /storage/emulated/0/Android/data/it.egaf/prefs.txt: open failed: EACCES (Permission denied).

In the config.xml plugin file I’ve specified some android permissions

<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.Manifest.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.Manifest.permission.READ_EXTERNAL_STORAGE"/>
</config-file>

but the problem still remain … :frowning:
Any suggests? What I’ve done wrong?
Thank you for any help.
Regards,
Michele


#3

I’ve solved using write and read function of the cordova file plugin.
Bye


#4

Hi @morticcino: Please help me detail. I saw the same error.


#5

Hi,
in my plugin I use read and write funtion of ionic file plugin.
Before read and write procedure stayed in java code.

Instead of:

JS
myplugin.dosomething()

JAVA
dosomething(){
java.io.File dir = android.os.Environment.getExternalStorageDirectory();
java.io.File yourFile = new java.io.File(dir, “file.txt”);
br = new java.io.BufferedReader(new java.io.FileReader(yourFile));

}

Now I do:
JS
myplugin.dosomething(file-plugin.read(file.txt))

JAVA
dosomething(String content){

}

I hope that I have been useful to you.
Regards,
Michele


#6

Thank you, @morticcino


#7

You’re welcome! …:wink: