Intent musicIntent = new Intent(); //use Action VIEW to launch app musicIntent.setAction(Intent.ACTION_VIEW); String mimeType = getMimeTypeFromFile(); // in your case it is audio Uri uri = " yourfile uri"; musicIntent.setDataAndType(uri,mimeType); startActivity(intent);
The default view application will be open if the mime type is changed, for the video mixer the mime type video will be opened, for the audio music player and for the image gallery.
If there are several players, then the Resolver action will be open.
Remember to catch an ActivityNotFoundException
In the music player ACTION_VIEW, the AudioPreview function is called with priority. there are other actions that handle this action, just check once with the action " com.android.music.PLAYBACK_VIEWER " instead of ACTION_VIEW or with it.
source share