[AC-4961] TiFileProxy: java.io.FileNotFoundException: /storage/emulated/0/com.example.sample/sample.txt: open failed: EACCES (Permission denied)
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-05-15T14:45:24.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | android, requestPermission |
Reporter | Jignesh Kasundra |
Assignee | Shak Hossain |
Created | 2017-05-12T06:35:10.000+0000 |
Updated | 2017-05-17T11:33:00.000+0000 |
Description
I am trying ro write/read file into the external storage device. but getting the (Permission denied) error. I have already applied run time request permission.
OSX, Titanium SDK 6.0.4 , Android Platform 6.0 , Android API 23
===============
[ERROR] : TiFileProxy: (main) [1353,1353] IOException encountered
[ERROR] : TiFileProxy: java.io.FileNotFoundException: /storage/emulated/0/com.example.sample/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:273)
[ERROR] : TiFileProxy: at org.appcelerator.titanium.io.TiFile.open(TiFile.java:336)
[ERROR] : TiFileProxy: at org.appcelerator.titanium.io.TiFile.write(TiFile.java:460)
[ERROR] : TiFileProxy: at org.appcelerator.titanium.TiFileProxy.write(TiFileProxy.java:287)
[ERROR] : TiFileProxy: at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
[ERROR] : TiFileProxy: at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:196)
[ERROR] : TiFileProxy: at org.appcelerator.kroll.KrollRuntime.runModule(KrollRuntime.java:241)
[ERROR] : TiFileProxy: at org.appcelerator.titanium.TiLaunchActivity.loadActivityScript(TiLaunchActivity.java:128)
[ERROR] : TiFileProxy: at org.appcelerator.titanium.TiLaunchActivity.windowCreated(TiLaunchActivity.java:183)
[ERROR] : TiFileProxy: at org.appcelerator.titanium.TiRootActivity.windowCreated(TiRootActivity.java:172)
[ERROR] : TiFileProxy: at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:682)
[ERROR] : TiFileProxy: at org.appcelerator.titanium.TiLaunchActivity.onCreate(TiLaunchActivity.java:169)
[ERROR] : TiFileProxy: at org.appcelerator.titanium.TiRootActivity.onCreate(TiRootActivity.java:161)
[ERROR] : TiFileProxy: at android.app.Activity.performCreate(Activity.java:6237)
[ERROR] : TiFileProxy: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
[ERROR] : TiFileProxy: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
[ERROR] : TiFileProxy: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
[ERROR] : TiFileProxy: at android.app.ActivityThread.-wrap11(ActivityThread.java)
[ERROR] : TiFileProxy: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
[ERROR] : TiFileProxy: at android.os.Handler.dispatchMessage(Handler.java:102)
[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)
[ERROR] : TiFileProxy: at libcore.io.Posix.open(Native Method)
[ERROR] : TiFileProxy: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
[ERROR] : TiFileProxy: at libcore.io.IoBridge.open(IoBridge.java:438)
[ERROR] : TiFileProxy: ... 26 more
Sample Code ============== app.js ------------
=============== tiapp.xml -------------
Hello, My understanding is you are trying to access the external storage and write there without allowing the permission during runtime. So, what you need to do is, you need to put your code of writing inside a button eventlistner and on window open you allow the access and click on the button to write and so forth. Now, your code works on second run on my device cause i allowed the permission on first run and the app remembers it. Thanks.
Hi , thanks! it's working on second run, I am able to read and write the file in external storage. but *how can I make it work on first run*. because even after I had read/write file on button click eventListener still not working first run and it throws error while click on button >>>TiFileProxy: java.io.FileNotFoundException: /storage/emulated/0/com.example.sample/sample.txt: open failed: EACCES (Permission denied) NOTE : I have also added requestPermission under window.open event
Hello, Take a look at my code below.
this works on first run. Thanks.
Hello, After using above code the issue still exist. first time app launch while click on write button , it throws same error. second app run it works fine. please can you check this.