1

I am trying to launch the MediaPlayer from a service, and its not wroking as expected. I m getting the following exception,

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.MUSIC_PLAYER flg=0x10000000 }

Please find the snippet of code that gets invoked in the service,

Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Android Manifest

<service android:name="com.lakshmi.shakenfun.AlertService" >
    <intent-filter >
        <action android:name="android.intent.action.MUSIC_PLAYER" />
    </intent-filter>
</service>

Please do let me know, where I am doing wrong.

My target platform is 8

Thanks, Ramesh

Sam
  • 86,580
  • 20
  • 181
  • 179
Ramesh Sangili
  • 1,633
  • 3
  • 17
  • 31
  • 3
    You can't start a `Service` using `startActivity(intent);`. To start a `Service` you use `startService(...)`. – Squonk Dec 31 '12 at 22:24
  • Are you trying to start the device's media player? If so, why do you have the `MEDIA_PLAYER` action defined on an `` of your own service? With respect to the error, apparently there is no activity on your device or emulator that supports that particular `Intent` action. – CommonsWare Dec 31 '12 at 23:37
  • I need to launch a media player from a service. I don't want to start a service. I referred this link to launch a media player from my service, http://stackoverflow.com/questions/3114471/android-launching-music-player-using-intent To simply launch the music player do: Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER); startActivity(intent); – Ramesh Sangili Jan 02 '13 at 00:06
  • I wanted to open the Media player by default and play the first song by default. Is it possible to do that? – Ramesh Sangili Jan 02 '13 at 00:35

2 Answers2

1

Perhaps your Target Platform of 8 is too low for that api? Do you have this music player loaded? https://play.google.com/store/apps/details?id=com.google.android.music&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5nb29nbGUuYW5kcm9pZC5tdXNpYyJd

  • You are right. I don't have this music player but after installing this app, the above code is working fine. But how to launch any music app without installing this particular app? – Atul Bhardwaj Jul 19 '13 at 07:00
1

MediaStore.INTENT_ACTION_MUSIC_PLAYER is deprecated from API 15 the new code is:

try {
    String pkgname = "com.sec.android.app.music";
    PackageManager pkgmanager = getPackageManager();
    Intent intent = pkgmanager.getLaunchIntentForPackage(pkgname);
    startActivity(intent);
} catch(Exception e) {
    // music player not found
}

Just add this code on your button listener and it will call the default music player.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
jai_b
  • 1,113
  • 7
  • 7