HOW TO USE CHOOSE FILE IN ANDROID WITHOUT USING BROWSE?

Pooja Malohtra

Total Post:47

Points:331
Posted by  Pooja Malohtra
Java  File 
 925  View(s)
Ratings:
Rate this:

I have an application on android phone. People will download pdf file before using my app, and the pdf file will be saved in a certain folder.

I know the absolute path of the folder, but I don't know the name of the new pdf file people download, so I can't get the absolute path of the pdf apparently.

Is there any method to choose the file by using maybe the file type? (Because I am sure that there is only one pdf file in that folder.) By the way, I don't want to choose file by browse.

Here is the stupid method I used before, but it can't match my demand anymore.

public static final String file_name = "//sdcard//Download//test.pdf";

File myFile = new File(file_name);

Any easy way to solve the problem? Thanks for your help sincerely.

  1. Tom Cruser

    Post:28

    Points:196
    Re: How to use Choose file in android without using browse?

    Below method will give all the PDF files in Download folder.

    String path = Environment.getExternalStorageDirectory().toString()+"/Download";

    File f = new File(path);       

    File files[] = f.listFiles();  

    for (File f : files)

         {

          String fullPath = f.getAbsolutePath();

          int dot = fullPath.lastIndexOf(".");

          String ext = fullPath.substring(dot + 1);

          if(ext.equals("pdf"))

          {

            //do something with f here

          }

         } 

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!