[
https://issues.apache.org/jira/browse/CB-9068?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tanase Butcaru updated CB-9068:
-------------------------------
External issue URL:
http://stackoverflow.com/questions/30417959/filewriter-write-failure-on-lollipop-when-no-ext-sdcard-present
> FileWriter.write() failure on Lollipop when no ext_sdcard present
> -----------------------------------------------------------------
>
> Key: CB-9068
> URL: https://issues.apache.org/jira/browse/CB-9068
> Project: Apache Cordova
> Issue Type: Bug
> Components: Android, Plugin File
> Affects Versions: 5.0.0
> Environment: Android Emulator (4.4.2, 5.0.1 and 5.1.1)
> Xperia Sola (with 4.4.4)
> Xperia Z3 Compact (5.0.2)
> ----
> Cordova 5.0.0
> cordova-android 4.0.0
> Reporter: Tanase Butcaru
> Priority: Blocker
> Labels: file, fileWriter, writer
>
> FileWriter write method fails on android lollipop versions when no external
> sdcard is present.
> Simple test case:
> {code:javascript}
> function fwriteTest(){
> console.log("START FILE WRITE!!");
> console.log("CDV dataDirectory: " + cordova.file.dataDirectory);
> window.resolveLocalFileSystemURL(cordova.file.dataDirectory,
> resolveLocalFSUrlWin, resolveLocalFSUrlErr);
> }
> function resolveLocalFSUrlErr(err){ console.log("resolve FS ERR: -- " +
> JSON.stringify(err)); }
> function resolveLocalFSUrlWin(dirEntry){
> console.log("resolve FS WIN!!");
> dirEntry.getFile('fileWriter.txt', { create: true, exclusive:
> false }, getFileWin, getFileErr);
> }
> function getFileErr(err){ console.log("get file ERR: -- " +
> JSON.stringify(err)); }
> function getFileWin(fileEntry){
> console.log("get file WIN!!");
> fileEntry.createWriter(
> function(writer){
> writer.onwrite = function(evt){
> console.log("Write to file WIN!!");
> alert("ALL GOOD!!");
> };
> writer.onerror = function(err){
> console.log("Write to file FAIL: -- " +
> JSON.stringify(err));
> }
> writer.write("sample text goes hereee");
> },
> function(err){
> console.log("create writer ERR: -- " +
> JSON.stringify(err));
> }
> );
> }
> //run test!
> fwriteTest();
> {code}
> AndroidManifest.xml contains the following permission, so it's all good here:
> {code:xml}<uses-permission
> android:name="android.permission.WRITE_EXTERNAL_STORAGE" />{code}
> I have two android devices, different android versions (4.4.4 and 5.0.2) and
> I have 3 android emulators with android 4.4.2, 5.0.1 and 5.1.1.
> I tested all environments with and without ext_sdcard (for emulators do not
> enter "Size" for Sd card option) and here are my results:
> {noformat}
> Android 4.4.4 with & without extSD (XPERIA Sola)
> ==================================
> LEVEL | TAG | TEXT
> =======================================
> I | chromium | [INFO:CONSOLE(228)] "START FILE WRITE!!", source:
> <...>
> --------------------------------
> I | chromium | [INFO:CONSOLE(229)] "CDV dataDirectory:
> file:///data/data/cdv.filewriter.issue/files/", source: <...>
> --------------------------------
> W | AssetFilesystem | Asset manifest not found. Recursive copies and
> directory listing will be slow.
> --------------------------------
> I | chromium | [INFO:CONSOLE(236)] "resolve FS WIN!!", source:
> <...>
> --------------------------------
> I | chromium | [INFO:CONSOLE(243)] "get file WIN!!", source: <...>
> --------------------------------
> D | TEST | cdvfile://localhost/files/fileWriter.txt: 23
> --------------------------------
> I | chromium | [INFO:CONSOLE(248)] "Write to file WIN!!", source:
> <...>
> ANDROID 4.4.2 without sdcard / with sdcard (EMULATOR)
> ==========================================
> < same output as XPERIA Sola >
> ANDROID 5.0.2 without extSD (XPERIA Z3 Compact)
> ===========================
> LEVEL | TAG | TEXT
> =======================================
> I | chromium | [INFO:CONSOLE(228)] "START FILE WRITE!!", source:
> <...>
> ---------------------------------------
> I | chromium | [INFO:CONSOLE(229)] "CDV dataDirectory:
> file:///data/data/cdv.filewriter.issue/files/", source: <...>
> ---------------------------------------
> W | AssetFilesystem | Asset manifest not found. Recursive copies and
> directory listing will be slow.
> ---------------------------------------
> I | chromium | [INFO:CONSOLE(236)] "resolve FS WIN!!", source:
> <...>
> ---------------------------------------
> I | chromium | [INFO:CONSOLE(243)] "get file WIN!!", source: <...>
> ---------------------------------------
> W | ContextImpl | Failed to ensure directory:
> /storage/sdcard1/Android/media/cdv.filewriter.issue
> ---------------------------------------
> I | chromium | [INFO:CONSOLE(253)] "Write to file FAIL: --
> {"type":"error","bubbles":false,"cancelBubble":false,"cancelable":false,"lengthComputable":false,"loaded":0,"total":0,"target":{"fileName":"","length":23,"localURL":"cdvfile://localhost/files/fileWriter.txt","position":0,"readyState":2,"result":null,"error":{"code":6},"onwritestart":null,"onprogress":null,"onwriteend":null,"onabort":null}}",
> source: <...>
> ANDROID 5.0.2 with extSD
> ========================
> < same output as 4.4.4 >
> ANDROID 5.0.1 & 5.1.1 without sdcard (EMULATOR)
> =====================================
> < same output as XPERIA Z3 Compact >
> ANDROID 5.0.1 & 5.1.1 with sdcard (EMULATOR)
> ==================================
> < same output as XPERIA Sola >
> {noformat}
> All results are from LogCat console from android-sdk/tools/monitor tool.
> I use Crosswalk 12-stable version as my default webview, but I have tested
> all this with System-webview too and the problem persists.
> As you can see from printed error on write fail - there is a error 6 code and
> from what I've read
> [here|https://github.com/apache/cordova-plugin-file#list-of-error-codes-and-meanings]
> it's a _NO_MODIFICATION_ALLOWED_ERR_ error.
> You can also replace _cordova.file.dataDirectory_ with any other path (i have
> tried _cacheDirectory_ and _tempDirectory_) or with a _FileSystem_ path like
> _LocalFileSystem.PERSISTENT_ (in this case you'll have to modify the
> _dirEntry.getFile_ into _dirEntry.root.getFile_ and the
> _resolveLocalFileSystemUrl_ with _requestFileSystem_ method and its
> arguments) - issue will persist!
> Am I missing some configurations/permissions or it's really a bug?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]