sudo
sudo

Reputation: 1525

how to show android file browser in windows platform

I want to show file list in android in windows platform. I used the method :

 private void browseToRoot() {
                browseTo(new File("C:\\");
    }

 private void browseTo(final File aDirectory){
              if (aDirectory.isDirectory()){
                 this.currentDirectory = aDirectory;
                     fill(aDirectory.listFiles());
              }else{
                     OnClickListener okButtonListener = new OnClickListener(){
                            // @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                                   // Lets start an intent to View the file, that was clicked...
                                Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW,
                                        Uri.parse("file://" + aDirectory.getAbsolutePath())); 
                                startActivity(myIntent);
                             }
                     };
                     OnClickListener cancelButtonListener = new OnClickListener(){
                             // @Override
                             public void onClick(DialogInterface arg0, int arg1) {
                                    // Do nothing
                            }
                     };
                     new AlertDialog.Builder(this)
                     .setTitle("Question")
                     .setMessage("Do you want to open that file?"+ aDirectory.getName())
                     .setPositiveButton("OK", okButtonListener)
                     .setNegativeButton("Cancel", cancelButtonListener)
                     .show();

             }
      }

But It doesn't work . If I change to "BrowseTo(new File("/"))" ,it work.

thanks for help

Upvotes: 0

Views: 406

Answers (2)

Sunil Kumar Sahoo
Sunil Kumar Sahoo

Reputation: 53647

Try with Environment.getRootDirectory() instead of "/"

Thanks Deepak

Upvotes: 0

ihrupin
ihrupin

Reputation: 6972

Android is a Linux-based OS.

You should use Linux-style paths to files

Upvotes: 1

Related Questions