1

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?

CrazyLearner
  • 782
  • 3
  • 11
  • 28

1 Answers1

0

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?

Community
  • 1
  • 1
Android
  • 427
  • 5
  • 14
  • I dont want to share any file, I want to open any type of file with supported applications or viewer which are installed in the devices... – CrazyLearner Jan 20 '14 at 10:17
  • edited try to do that, mine answer is just and example, you should implement your own logic for doing you job – Android Jan 20 '14 at 11:29
  • Thanks Android for your help, finally I got the answer from your mentioned link and edited your answer for other's help. – CrazyLearner Jan 21 '14 at 04:03