I tried many codes on the stackoverflow.com
I can't receive any action from onReceiver method. When i receive any signal from onReceiver, I will add spesific if conditions into onReceiver for (long press etc.) But I cant even able to receive any signal from onReceiver.
What should I do for detecting headset button presses?
Headset means earphone(for phone), I hope I explained my issue Thanks in advance :)
Here is my codes: (Also added Bluetooth permission)
@Override protected void onResume() { super.onResume(); IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON); registerReceiver(headsetBroadcastingClass,filter); } Broadcast Receiver class:
public class HeadsetBroadcastingClass extends BroadcastReceiver { public HeadsetBroadcastingClass() { super(); System.out.println("initialized"); } @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "action detected", Toast.LENGTH_SHORT).show(); } } And here is my manifest.xml:
.... </activity> <service android:name=".MusicService" /> <receiver android:name=".HeadsetBroadcastingClass"> <intent-filter android:priority="999999999"> <action android:name="android.intent.action.MEDIA_BUTTON" /> </intent-filter> </receiver> </application> https://stackoverflow.com/questions/65556444/how-to-detect-headset-button-click-with-android-broadcast-receiver January 04, 2021 at 08:43AM
没有评论:
发表评论