1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

Unable to get android to download misc files from webserver!


Last Updated:

  1. phodat

    phodat New Member This Topic's Starter

    Joined:
    Nov 24, 2010
    Messages:
    4
    Likes Received:
    0
    I am attempted to download some files off of a web server down to my android phone. I would prefer the download be put on the SDcard but at this point it doesn't matter. I am become quite frustrated with this.

    When I attempt to download, I get all the way to the end without exceptions thrown and I check for its existence and do not find it. In addition I cannot find the files on my SD card when looking via DDMS. When I do a directory check, I do not get any errors that the directory does not exist.

    I suspect some type of permissions issue but I can't seem to find the answer. I have verified that the web page script (PHP) is working by trying on my browser. I am able to down the file to my hearts content


    thanks in advance!!!

    private boolean WriteBytesToFile(String path,byte[] bytes)
    {
    boolean returnval =false;

    try
    {

    File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyDir" + path);

    File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyDir" + path).getParentFile();
    if (!directory.exists() && !directory.mkdirs()) {
    logger.e("WriteBytesToFile","path does not exist ");
    }

    FileOutputStream fos = openFileOutput(path,MODE_WORLD_READABLE);
    logger.e("WriteBytesToFile","Length of file to write : " +Integer.toString(bytes.length));
    fos.write(bytes);
    fos.flush();
    fos.close();
    if (file.exists())
    {
    logger.e("WriteBytesToFile","File Exists after download");
    returnval = true;
    }
    else
    {
    logger.e("WriteBytesToFile","File Doesn't Exist after download");
    returnval = true;
    }
    }
    catch(Exception ex)
    {
    logger.e("WriteBytesToFile","Exception : " + ex.toString());
    }
    return returnval;
    }

    }
     

    Advertisement
  2. takeshi

    takeshi Well-Known Member

    Joined:
    Dec 6, 2009
    Messages:
    3,354
    Likes Received:
    281
    Astro has an option in it to allow the browser to download any type of file. I'm sure there are other apps and ways to achieve this as well.
     
  3. phodat

    phodat New Member This Topic's Starter

    Joined:
    Nov 24, 2010
    Messages:
    4
    Likes Received:
    0
    Please ignore, posted in wrong forum
     

Share This Page

Loading...