0

The audio file not playing intent is providing null, no music apps found,while some other apps capable to do this by playing it with different music app.But here in my case it goes to the else part.

This is not working on android PIE haven't tested with older versions.

We have tried many solutions like Android launching music player using intent but its not working maybe android has updated the music play usage.

Intent movieIntent = new Intent();
movieIntent.setPackage("com.google.android.music");
movieIntent.setAction(Intent.ACTION_VIEW);
movieIntent.setDataAndType(Uri.parse(vFilePath),"audio/*");
//Play Music With Installed Apps 
if(movieIntent.resolveActivityInfo( context.getPackageManager(),0)!=null){
   context.startActivity(movieIntent);
}
else{
   //
}

None of the old solutions are working I am looking for an updated solution.

1 Answers1

0

Step #1: Get rid of:

movieIntent.setPackage("com.google.android.music");

Step #2: Use a concrete MIME type, not audio/*. It is your content, so you know what the MIME type is.

Step #3: If vFilePath is supposed to be a filesystem path, use FileProvider to get a Uri to use, rather than Uri.parse(). Also, note that your vFilePath approach may not work on Android 10+, as you have limited access to the filesystem.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491