[TIMOB-20440] Android 6.0: writing to applicationDataDirectory fails without External storage permissions
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-03-21T08:07:24.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.4.0, Release 5.3.0 |
Components | Android |
Labels | n/a |
Reporter | Manuel Lehner |
Assignee | Hieu Pham |
Created | 2016-02-15T10:44:46.000+0000 |
Updated | 2017-05-12T06:09:00.000+0000 |
Description
Before targeting API 23 on Android this function worked fine for storing remote images in the applicationDataDirectory:
function onImageLoad(e){
var imageDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'images/cache');
if (! imageDir.exists()) {
imageDir.createDirectory();
}
var image = _.last(e.source.image.split('/'));
var localFile = Ti.Filesystem.getFile(imageDir.resolve(), image);
localFile.write(e.source.toBlob());
e.source.removeEventListener('load', onImageLoad);
}
With Titanium 5.2.0 targeting Android API >= 23 : file.write
does not work throwing this error:
[ERROR] TiFileProxy: (KrollRuntimeThread) [407,3676] External storage permissions missing
Writing to the __applicationDataDirectory__ should not require this permission.
*Expected*
file.write()
should work.
*Result*
file.write()
fails with
ERROR: External storage permissions missing
Attachments
File | Date | Size |
---|---|---|
Screen Shot 2016-02-16 at 2.47.35 PM.png | 2016-02-16T08:48:07.000+0000 | 53326 |
Screen Shot 2016-02-17 at 11.38.49 AM.png | 2016-02-17T05:42:49.000+0000 | 67982 |
Hello, I tried to reproduce the issue of writing files in Android. Below is a sample code i am using. I have tested with SDK 5.2.0.v20160114021251 and in Nexus 5 Android 6.0.0. Writing to files is working as expected. See the screenshot.
Thank you for testing. I've just created a new clean project and tested your code on both of my devices, a Nexus 5 and Nexus 5X (both with Android 6.0.1). But I get different results. On the Nexus 5 it works as expected like shown in your screenshot. On the Nexus 5X The Alert body is empty and the console prints this error:
Could it be this is an arm64 issue?
Hello, I tested again in Nexus 5X Android 6.0.0. The issue is not reproducible. Writing to files is working as expected. See the screenshot.
It's because you've granted the Storage permission. Can you please disable this permission in the Settings and try again? This is the problem I'm trying to point out. The File Proxy should distinguish between internal and external storage. Writing into *applicationDataDirectory* does not require READ_EXTERNAL_STORAGE permission but it checks for it and fails though.
Not sure if this may be related to this issue but sometimes my app crashes with this exception:
Yes, I can confirm this External storage permissions problem on nexus 9, it works on SDK <= 5.1.2, but not 5.2.0
Not trying to be rude or pushy, can we expect the fix for this in 5.3.0. or along with the Google Play Store X509 security fix? :) We do not want to add the external storage permission as a fix as it would give wrong impression to the user.
Hello, I've the same problem on Moto X Play (XT1562) with Android 6.0 and SDK 5.2.0GA with or without Android External Permission. The same code works on Xiaomi MI-4C with MIUI 6.1.28 (Android 5.1.1) without user permission and SDK 5.2.0GA. var photo = Ti.Network.createHTTPClient(); photo.open('GET', 'someurl'); photo.onload = function() { var dir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'biodiversita'); if (!dir.exists()) { dir.createDirectory(); } f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "biodiversita/name.jpg"); f.write(this.responseData); }; photo.send(); I tried to use SDK 5.1.2 without Android External Permission on the same Moto X Play and it works.
master PR: https://github.com/appcelerator/titanium_mobile/pull/7858
[~manuellehner] Your crash log earlier with regards to
is due to another issue which is solved in TIMOB-20434. The fix is in 5.2.0. Just fyi.
I am on a nexus 7 with android 6.0.....I am running SDK 5.2.0 and keep getting these error. [ERROR] : TiFileProxy: (KrollRuntimeThread) [11,30395] External storage permissions missing. Do we know when this is fixed?
[~peterladis] Is your code similar to what's being mentioned in this ticket?
Master PR https://github.com/appcelerator/titanium_mobile/pull/7858 Merged. And PR https://github.com/appcelerator/titanium_mobile/pull/7871 for fixing tests Merged.
[~msamah] what version(s) are we fixing this in?
[~fokkezb] Thanks for pointing that out. This is in master, fix version is -6.0.0.- 5.4.0. (Incorrectly mentioned it to be 6.0.0.)
I got same error with Titanium.Filesystem.tempDirectory and why it not fixed for 5.2.1 ?
[~falko] Thanks for bringing this up. 5.2.1 is already scheduled and it's too late to bring this into that. Instead, we'll add this to the next patch (5.3.0).
OK. This PR has fix for Titanium.Filesystem.tempDirectory or Titanium.Filesystem.applicationDataDirectory only?
This fix is for applicationDataDirectory but it also works for the tempDirectory. Sample code:-
Permission is not required.
5_3_X PR: https://github.com/appcelerator/titanium_mobile/pull/7872 (Merged)
The target fix version on 5.3.0. @Ashraf Abu, can you please let us know the date by when we can expect the GA for 5.3.0. One of the new application that we are developing is targeting to save data in application data folder.
@Andrey Tkachenko Thanks for sharing the link. So we can expect the GA around Apr 11 and the RC before that, which is a good news.
@Soumya Kanti Kar You can add PR to 5.2.X branch and compile SDK at any time.
[~falko] based on your log it seems you are trying to use
tempDirectory
which TIMOB-20470 is about. In that case, please follow that jira. For the issue of this ticket ofapplicationDataDirectory
this is resolved. Thanks!@Ashraf Abu Yes I point it in my comment. But I answered to your comment.
Verified he fix. Writing to applicationDataDirectory doe not fail without storage permissions. Closing. Environment: Appc Studio : 4.6.0.201604041329 Ti SDK : 5.3.0.v20160404105211, 5.4.0.v20160406101605 Ti CLI : 5.0.7 Alloy : 1.8.5 MAC El Capitan : 10.11.4 Appc NPM : 4.2.5-2 Appc CLI : 5.3.0-12 Node: 4.2.2 Nexus 6 - Android 6.0.0
Since Android6 you need runtime permissions. There is a module (Ti.permissions). All details on github.
[~titanium@webmasterei-hamburg.de] with the fixes for this ticket you shouldn't need to. Could you verify that?
I never seen problems by writing to applicationdata folder.
OK, what exactly does your comment relate to then? {quote} Since Android6 you need runtime permissions. There is a module (Ti.permissions). All details on github. {quote}
I thought the ticket was in realtion to the new perfmissions. Was mistake.
Hello, I got the latest SDK- 5.3.0.GA Appcelerator Studio- 4.6.0.201605201934 Node=- V4.4.4 But, still the issue is not resolved. Below is the error.
All the permissions are already in tiapp.xml file. Thanks
I've just updated all the stable versions of 2nd June and I have exactly the same problem of Bhavin Bhavsar.
I am getting same issue on Titanium sdk 6.0.4 , Android Platform 6.0 , Android API 23 -----------------------------
for the above error : I am writing/reading file from the external storage device. tiapp.xml ==============
app.js =============