I managed to get my headset buttons get recognized by my app when pressed, but one of the buttons needs to call a method that's in MyCustomActivity. The problem is onReceive's 1st parameter is a Context that cannot be cast to Activity and so I am forced to implement my BroadcastReceiver as an inner class inside MyCustomActivity.
So far so good but how do I register this inner MediaButtonEventReceiver in the manifest?
For the independent class, this was simple:
<receiver android:name=".RemoteControlReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
What is the trick/syntax to do the same for MyCustomActivity's mReceiver?
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context ctx, Intent intent) {
// ...
}
}
new BroadcastReceiver()
instantiated again in onCreate(), I am going to try this one more time and report back how it worked. +1 for now. – Preventer