How to get a list of installed media players

后端 未结 6 2105
春和景丽
春和景丽 2020-12-06 07:48

In my app I have a menu item that I want to open up the user\'s preferred media player, only interested in audio. Ideally the first time the user chooses this item it would

6条回答
  •  天命终不由人
    2020-12-06 08:08

    Intent resolveIntent = new Intent(Intent.ACTION_VIEW);
    if (type.startsWith("audio/*")) {
        Uri uri = Uri.withAppendedPath(
                MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
        resolveIntent.setDataAndType(uri, type);
    } else if (type.startsWith("video/*")) {
        Uri uri = Uri.withAppendedPath(
                MediaStore.Video.Media.INTERNAL_CONTENT_URI, "1");
        resolveIntent.setDataAndType(uri, type);
    } else if (type.startsWith("application/pdf")) {
        resolveIntent.setType(type);
    }
    
    List pkgAppsList = mContext.getPackageManager().queryIntentActivities(resolveIntent, PackageManager.GET_RESOLVED_FILTER);
    

    Here is my solution, If you want get a list of "video/" or "audio/" APPs, you should use "setDataAndType"; But if you want to get a list of "text/*" or "pdf" APPs, you can use "setType".

提交回复
热议问题