Every manufacturer will have its default music player, but if you still want to open default android music player which google provides i.e Google Play Music then you can open it with following code:-
This code will open Google Play Music if its installed otherwise it will open some other music player.
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//Check for Google Play Music exist
if (isPackageInstalled("com.google.android.music", getPackageManager()))
{
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.google.android.music");
startActivity(LaunchIntent);
}
else
{
else
{
//Your previous code goes here
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(Environment.getExternalStorageDirectory().getPath()+"/alarm.mp3");
if (file!=null)
{
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
}
else
{
Toast.makeText(Music.this,"Sound Track missing",Toast.LENGTH_LONG);
}
}
}
private boolean isPackageInstalled(String packagename, PackageManager packageManager)
{
try
{
packageManager.getPackageInfo(packagename, 0);
return true;
}
catch (PackageManager.NameNotFoundException e)
{
return false;
}
}