FIle API - Telephony?

Can anyone explain how to list the file folder on a page using the Phonegap Android File APIs?

I would like to list all the .mp3 files, if possible, but I read all the documents of the telephone table ( http://docs.phonegap.com/en/1.0.0/phonegap_file_file.md.html ) and I can not think about it at all !

+4
source share
4 answers

it's a bit of a pain in @ $$, but doable. Start with this code:

 document.addEventListener("deviceready", onDeviceReady, false); // PhoneGap is ready // function onDeviceReady() { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail); } function onFileSystemSuccess(fileSystem) { fileSystem.root.getDirectory("Music", {create: false, exclusive: false}, getDirSuccess, fail); } function getDirSuccess(dirEntry) { // Get a directory reader var directoryReader = dirEntry.createReader(); // Get a list of all the entries in the directory directoryReader.readEntries(readerSuccess,fail); } function readerSuccess(entries) { var i; for (i=0; i<entries.length; i++) { // Assuming everything in the Music directory is an mp3, go nuts // otherwise check entries[i].name to see if it ends with .mp3 } } 

I am writing all this sample code outside the IDE, so there may be errors, but this should make you.

+11
source

Paul, have you added the fail () function? This will be required in the Simon code example. Example api docs :

 function fail(evt) { console.log(evt.target.error.code); } 
+2
source

You can also save one step in Simon's code if you just want to get a proof of concept, since fileSystem.root is already dirEntry (and this saves you a potentially buggy step when using a directory name, such as "Music", which may or may not be) :

 function onFileSystemSuccess(fileSystem) { var directoryReader = fileSystem.root.createReader(); // Get a list of all the entries in the directory directoryReader.readEntries(readerSuccess,fail); } function readerSuccess(entries) { var i;....... 

which works for me.

However, I get the contents of the application root directory, apparently my application is called be.qan.blaActivity, so if I ask for its fileSystem.root.name , it will tell me "be.qan" and fileSystem.root.path is undefined. So my question here is: how can I get out of this sandbox if it is really what I'm sitting in and can I access the sd_card directories or other parts of the file system (since iOS still doesn’t even have external storage) ?

What I get as file names in readerSuccess are names like "databases", "app_database", "cache" and "lib" that don't even appear when I search using Astro FileManager, so I strongly believe that they are part of the virtual file system created by Cordor for an application or so. Probably, I still have a lot of things that are missing, and people are more knowledgeable than I can establish me directly, but this is what I guess so far.

+2
source

Hi, I am using this code and it works for me .. can try it

 $('#recordingList').on('pagecreate', function(event) { generateRecordingList(); }); function generateRecordingList(){ //request for the file system window.resolveLocalFileSystemURI("file:///sdcard/rem", onFileSystemSuccess, onError); } function onFileSystemSuccess(fileSystem){ alert("FileSystem success : " + fileSystem.name); } function onError(error){ alert(error.target.error.code); } 
0
source

Source: https://habr.com/ru/post/1384754/


All Articles