Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5086] Android 6.0 : open failed: EACCES (Permission denied) , Even storagePermission is true on emulator

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2017-07-20T18:41:47.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsandroid
ReporterJignesh Kasundra
AssigneeShak Hossain
Created2017-07-14T11:25:56.000+0000
Updated2017-07-20T18:41:47.000+0000

Description

I am facing the below error while writing/reading the file in external storage The external file permission is already allowed Tested on Titanium SDK 6.1.0 Emulator - Android 6.0 (API 23) Please also check the shared image of emulator ==============================================
TiFileProxy: (main) [44314,50797] IOException encountered
[ERROR] :  TiFileProxy: java.io.FileNotFoundException: /storage/emulated/0/com.info.external/sample.txt: open failed: EACCES (Permission denied)
[ERROR] :  TiFileProxy: 	at libcore.io.IoBridge.open(IoBridge.java:452)
[ERROR] :  TiFileProxy: 	at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
[ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.io.TiFile.getOutputStream(TiFile.java:289)
[ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.io.TiFile.open(TiFile.java:352)
[ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.io.TiFile.write(TiFile.java:476)
[ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.TiFileProxy.write(TiFileProxy.java:305)
[ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:872)
[ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1095)
[ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:360)
[ERROR] :  TiFileProxy: 	at android.os.Handler.dispatchMessage(Handler.java:98)
[ERROR] :  TiFileProxy: 	at android.os.Looper.loop(Looper.java:148)
[ERROR] :  TiFileProxy: 	at android.app.ActivityThread.main(ActivityThread.java:5417)
[ERROR] :  TiFileProxy: 	at java.lang.reflect.Method.invoke(Native Method)
[ERROR] :  TiFileProxy: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
[ERROR] :  TiFileProxy: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
[ERROR] :  TiFileProxy: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
======================================= app.js code ==========================================

var storePermission = "android.permission.WRITE_EXTERNAL_STORAGE";
 
var storagePermission = "android.permission.READ_EXTERNAL_STORAGE";
 
var hasStorePermission = Ti.Android.hasPermission(storePermission);
 
var hasStoragePermission = Ti.Android.hasPermission(storagePermission);
 
var permissionsToRequest = [];
 
var win = Ti.UI.createWindow({
 
    title : 'mywin',
 
    backgroundColor : '#fff',
 
    width : Ti.UI.FILL,
 
    height : Ti.UI.FILL
 
});
 
win.open();

win.addEventListener('open',function(){

		if (!hasStorePermission) {
		 
		    permissionsToRequest.push(storePermission);
		    Ti.API.info("PUSHED  1.WRITE_EXTERNAL_STORAGE");
		
		}
		 
		if (!hasStoragePermission) {
		 
		    permissionsToRequest.push(storagePermission);
		    Ti.API.info("PUSHED... 2.READ_EXTERNAL_STORAGE");
		 
		}
		 
		if (permissionsToRequest.length > 0) {
		 
		    Ti.Android.requestPermissions(permissionsToRequest, function(e) {
		 		
		 		Ti.API.info('Requesting Permission', e);
		 		
		        if (e.success) {
		 
		            Ti.API.info("SUCCESS");
		 
		        } else {
		 
		            Ti.API.info("ERROR: " + e.error);
		 
		        }
		 
		    });
		 
		}
		
		
		
});
 
 
var btn1 = Ti.UI.createButton({
 
    title : 'Write',
 
    top : 60
 
});
 
win.add(btn1);
 
 
 
btn1.addEventListener('click', function() {
 
 	
 	if(Ti.Filesystem.hasStoragePermissions()){
 		
 		var localPath = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory).nativePath;
 
   		var sampletxtvar = Ti.Filesystem.getFile(localPath, "sample.txt");
 
 		sampletxtvar.write("this is my sample text");
 
  		alert("\n Storage Permission :: " + Ti.Filesystem.hasStoragePermissions() + "\n File Writable :: "+sampletxtvar.writable +"\n File Content :: " +sampletxtvar.read().text);
  		
 	}
});
========================== tiapp.xml ==========================

 <android xmlns:android="http://schemas.android.com/apk/res/android">
        <manifest android:imeOptions="flagNoExtractUi"
            android:versionCode="1" android:versionName="1.0">
            <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/>
            <uses-permission android:name="android.permission.INTERNET"/>
            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
            <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
        </manifest>
    </android>

Attachments

FileDateSize
Screen Shot 2017-07-14.png2017-07-14T11:18:45.000+000051067

Comments

  1. Sharif AbuDarda 2017-07-14

    Hello, Can you please try it on real device with external storage?
  2. Jignesh Kasundra 2017-07-17

    Hello Sharif, thanks, I have tested on real device and it's working fine. please close this issue

JSON Source