-2

enter image description here

IntentFiLter iF IntentFiLter();
iF.addAction("com.android.music.metachanged");
iF.addAction("com.htc.music.metachanged");
iF.addAction("fm.last.android.metachanged");
iF.addAction("com.sec.android.app.music.metachanged");
iF.addAction("com.nullsoft.winamp.metachanged");
iF.addAction("com.amazon.mp3.metachanged");
iF.addAction("com.miui.player.metachanged");
iF.addAction("com.Peal.IMP.metachanged");
iF.addAction("com.sonyericsson.music.metachanged");
iF.addAction("com.Pdio.andPoid.metachanged");
iF.addAction("com.samsung.sec.android.MusicPlayeP.metachanged");
iF.addAction("com.andPew.apollo.metachanged");

registerReceiver(mReceiveP, iF);

The Problem is when I first open app it doesn't show the song's name. But now when the app is opened and next song is played it displays the name correctly. Something needs to be done when I first open the app so it automatically gets current song playing.

Please help

Community
  • 1
  • 1
Mehul Parmar
  • 347
  • 4
  • 21

1 Answers1

0

You are registering an IntentFilter to receive broadcasts of the different music players. Whenever a song started (as in starts to play), the music players broadcast this information. When your app starts, the current song is already playing (as in started to play before app start), so there is no broadcast for it.

You could create a Service that is registered to the BroadcastIntent that stores the song info into e.g. SharedPrefs for your app to retrieve when starting.

Florian Barth
  • 1,392
  • 12
  • 25
  • I'll be using the service that is registered to the BroadcastIntent that stores the song info. But that service needs to be running all the time. how to do that? – Mehul Parmar Dec 16 '15 at 10:39
  • http://developer.android.com/guide/components/services.html might be a good point to start. It does not need to running all the time. With the broadcast receiver the os will awaken it on the relevant broadcast events – Florian Barth Dec 16 '15 at 11:09
  • so you are saying as soon as some media player will broadcast, my service will automatically starts ? which type of service i have to use, can you be specific, please – Mehul Parmar Dec 16 '15 at 16:45