0

Android MediaButtonReceiver - is blocking event but do not handles it. Log is empty. Also - there is no headphone icon on the bar. Before experimenting with my code icon was there, and the button was starting and stopping the music.

code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE);
    manager.registerMediaButtonEventReceiver(new ComponentName(getPackageName(), MediaButtonReceiver.class.getName())); 
}

public class MediaButtonReceiver extends BroadcastReceiver
{
     @Override
     public void onReceive(Context context, Intent intent)
     {
             //doing nothing
         Toast toast1 = Toast.makeText(Context, intent.getAction(), Toast.LENGTH_SHORT);
         toast1.show(); 
         //doing nothing
        TextView t = (TextView)findViewById(R.id.textView1); 
        t.setText("received");
    (...)

Manifest:

    <receiver android:name="com.example.brom.MainActivity.MediaButtonReceiver">  
      <intent-filter android:priority="1000" >
            <action android:name="android.intent.action.MEDIA_BUTTON"></action>  
      </intent-filter>  
    </receiver>

Android is getting the event for sure - because screen is waking up, when I press the button.

1 Answers1

0

It is working after spliting project in two class files. The problem may be in the manifest declaration.

Now it is: