Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7752033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:41:53+00:00 2026-06-01T11:41:53+00:00

I am trying to open the SD card and upload a file in Android

  • 0

I am trying to open the SD card and upload a file in Android using Phonegap. Below is the code where I am appending the SD card content to my HTML, but nothing is displaying. I am using cordova.js, jquery1.7.1.js. Below is my code:

My Javascript:

function onDeviceReady() {
    getFileSystem();
}

function getFileSystem() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
        function(fileSystem) { // success get file system
            root = fileSystem.root;
            listDir(root);
        }, 
        function(evt) { // error get file system
            console.log("File System Error: "+evt.target.error.code);
        }
    );
}

function listDir(directoryEntry) {
    if (!directoryEntry.isDirectory) 
        console.log('listDir incorrect type');

    $.mobile.showPageLoadingMsg(); // show loading message

    currentDir = directoryEntry; // set current directory
    directoryEntry.getParent(
        function(par) { // success get parent
            parentDir = par; // set parent directory
            if ((parentDir.name == 'sdcard' && currentDir.name != 'sdcard') || parentDir.name != 'sdcard') 
                $('#backBtn').show();
        }, 
        function(error) { // error get parent
            console.log('Get parent error: ' + error.code);
        }
    );

    var directoryReader = directoryEntry.createReader();
    directoryReader.readEntries(
        function(entries) {
            var dirContent = $('#dirContent');
            dirContent.empty();

            var dirArr = new Array();
            var fileArr = new Array();
            for (var i=0; i < entries.length; ++i) { // sort entries
                var entry = entries[i];
                if (entry.isDirectory && entry.name[0] != '.') 
                    dirArr.push(entry);
                else if (entry.isFile && entry.name[0] != '.') 
                    fileArr.push(entry);
            }

            var sortedArr = dirArr.concat(fileArr); // sorted entries
            var uiBlock = ['a','b','c','d'];

            for (var i=0; i < sortedArr.length; ++i) { // show directories
                var entry = sortedArr[i];
                var blockLetter = uiBlock[i%4];
                //console.log(entry.name);
                if (entry.isDirectory)
                    dirContent.append('<div class="ui-block-' + blockLetter + '"><div class="folder"><p>' + entry.name + '</p></div></div>');
                else if (entry.isFile)
                    dirContent.append('<div class="ui-block-' + blockLetter + '"><div class="file"><p>' + entry.name + '</p></div></div>');
            }
            $.mobile.hidePageLoadingMsg(); // hide loading message
        }, 
        function(error) {
            console.log('listDir readEntries error: ' + error.code);
        }
    );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:41:54+00:00Added an answer on June 1, 2026 at 11:41 am

    Have you taken a look in the Cordova API Documents? I Tried this sample code and it worked just fine. Link to API and the sample code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to open a popup with nothing but the content using javascript in
im trying to open a file using StreamReader and ive to set a Encoding,
I'm trying to open a Microsoft Excel file in a C# program using the
I am trying to open a word document using window.open as below window.open(myworddoc.doc); It
Im trying to get image using webservice and saved to sd card. The file
Using Python I am trying to analyze a tab delimited file. I open the
I am trying download zip file to SD card. I download it correctly, but
I'm trying open a txt file and read it, but I'm getting a type
When trying to open a file using this command: $fd = fopen('majestic_files/majestic_record.txt','w'); I get
I am trying open a new window using url.Action. And the new Window url

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.