Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the location of file created by Cordova File Plugin?

I have used Cordova File Plugin to create files on mobile device. Below is the code to create files:

window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (dir) {    alert(cordova.file.dataDirectory);    dir.getFile("log.txt", { create: true }, function (file) {           alert("got the file: "+ file.name + ', ' + file.fullPath);    }); }); 

When I deploy the app on my android phone, the file will create successfully, but I can't find the created file on my device.

Although cordova.file.dataDirectory is pointing to file:///data/data/io.cordova.myappId/files/ path on my device, the io.cordova.myappId folder doesn't exist in data>data path, but exists in Android>data path. By the way, I checked both storage>Android>data>io.Cordova.myappId>files & storage>data>data and the file doesn't exist.

Is this because:

The created file is located in another place, so where can I find that?

or

Because it's private and my file manager doesn't have access to it, so how can I change the permission setting to have a public file?

like image 605
Asieh Mokarian Avatar asked Jan 09 '16 13:01

Asieh Mokarian


People also ask

Where is the file saved by Cordova file plugin on iOS?

There are two valid locations to store persistent files on an iOS device: the Documents directory and the Library directory. Previous versions of the plugin only ever stored persistent files in the Documents directory.

What is Cordova plugin file?

This plugin implements a File API allowing read/write access to files residing on the device. This plugin is based on several specs, including : The HTML5 File API http://www.w3.org/TR/FileAPI/

Where is plugin XML in Cordova?

The plugin. xml file is an XML document in the plugins namespace: http://apache.org/cordova/ns/plugins/1.0 .


1 Answers

Why I can't find the file on my device?

The file is created successfully but I can't find that on my device because the dataDirectory path which I indicates to create the file, is a private path and my device file manager doesn't have access to it (base on this table). Actually dataDirectory is an Internal Storage option.

Internal Storage: Store private data on the device memory.

You can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.(reference)

How to create a public file?

So, to create a file on my device that I can access it with the file manager, I have to use one of public path options like:externalDataDirectory. Before, I was thinking it is for storing files on an external SD Card that I had not on my phone, so I didn't test it. But testing it today, it creates the file on my internal device storage in Android/data/<app-id>/files path which is public and I can access it with device file manager.

Actually the term internal and external was misleading for me while external storage can be a removable storage media (such as an SD card) or an internal (non-removable) storage(reference).

like image 114
Asieh Mokarian Avatar answered Oct 12 '22 16:10

Asieh Mokarian