How to use or create android default fileopenpicker?

141 views Asked by At

I have a list of different types of files such as pdf, audio(mp3), video etc. I want to open those file using onClick event of the list items with supported viewer or applications. For example if the selected file will be an video file then, a dialog will be appeared having a list of installed as well as the default video players as below:

enter image description here

Can anyone help or guide me how to do that?

1

There are 1 answers

3
Android On BEST ANSWER

you should implement a chooser, like the example below,

 Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");//TYPE OF THE CONTENTS,this is for text
    shareIntent.putExtra(Intent.EXTRA_TEXT, noteTitle);//PUT THE EXTRA
 //THIS IS THE LOGIC FOR THE CHOOSER
    Intent chooser = Intent.createChooser(shareIntent,getString(R.string.share_dialog_title));


    PackageManager manager = getPackageManager();
    List<ResolveInfo> activities = manager.queryIntentActivities(chooser, 0);
    if(activities.size() > 0) {
        startActivity(chooser);
    } else {
        Toast.makeText(NoteListActivity.this, R.string.no_activities_for_action, Toast.LENGTH_LONG).show();
    }
}

EDIT also check this question, and combine my answer with the answer of this question nad you will get the result Launching an intent for file and MIME type?