1

I am trying to register a receiver using java and not the manifest, as I don't need this receiver work when my app is close.

If I use the manifest my receiver work well:

 <receiver android:name=".services.PlayerService$RemoteControlReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.MEDIA_BUTTON" />
        </intent-filter>
    </receiver>

If I register it in my activity without the manifest, this don't work at all:

IntentFilter filter = new IntentFilter();
    {
        filter.addAction("android.intent.action.MEDIA_BUTTON");
    }

    registerReceiver(RemoteControlReceiver, filter);

I don't need to use the manifest, as I want to control the headset button only when my app is open.

Giuseppe
  • 1,079
  • 13
  • 31
  • is your class really has this name with $ symbol. PlayerService$RemoteControlReceiver – Padma Kumar Jun 06 '12 at 15:13
  • Check this SO thread it will help you [Programmatically register a broadcast receiver](http://stackoverflow.com/questions/4805269/programmatically-register-a-broadcast-receiver) Share with me if still you get any trouble. – swiftBoy Jun 06 '12 at 15:16

1 Answers1

2

use Intent.ACTION_MEDIA_BUTTON instead of android.intent.action.MEDIA_BUTTON as;

IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);    
filter.setPriority(10000);    
registerReceiver(RemoteControlReceiver, filter);  
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213