In Android, How can I display an application selector based on file type?

后端 未结 2 421
悲哀的现实
悲哀的现实 2021-01-02 20:01

Apologies if this has already been answered - if someone can point me to an already-answered question, that would be great...

Very simply, I would like to be able to

2条回答
  •  心在旅途
    2021-01-02 20:19

    To get the applications that can successfully open a given intent you'll use the PackageManager. Simply construct the intent as above and then use this code to get the applications that can handle the intent.

    Intent myIntent = new Intent();
    myIntent.setAction(Intent.ACTION_VIEW);
    myIntent.addCategory("android.intent.category.LAUNCHER");
    myIntent.setType("mp3");    
    
    PackageManager manager = getPackageManager();
    List info = manager.queryIntentActivities(
        myIntent, PackageManager.MATCH_DEFAULT_ONLY);
    

    This will give you all the information on the programs that can handle the intent, including icon, and packagename. You can then create a dialog box with these options and save the option the user chooses.

提交回复
热议问题