How to use Choose file in android without using browse?

Total Post:47

Java  File 
 1316  View(s)
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. Post:28

    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);
            //do something with f here

      Modified On Apr-06-2018 06:21:52 AM