How To Detect Click Event Of Connected Bluetooth Peripheral Device (selfie Stick)?
I have Selfie stick connected to my phone. I am able to find device ID using below code: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(
Solution 1:
I found the answer. It was very simple. Just override onKeyDown()
method of Activity.
@OverridepublicbooleanonKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stubreturnsuper.onKeyDown(keyCode, event);
}
Here keyCode
is the event name returned.
Solution 2:
I have made slight modifications in your code. Please see if its helpful
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
IntentFiltera_filter=newIntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
this.registerReceiver(mReceiver, a_filter);
IntentFilterb_filter=newIntentFilter(Intent.ACTION_CAMERA_BUTTON);
**b_filter.setPriority(1000);**
this.registerReceiver(mReceiver, b_filter);
}
//The BroadcastReceiver that listens for bluetooth broadcasts
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
publicvoidonReceive(Context context, Intent intent) {
String action = intent.getAction();
device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
//Device is now connected
Toast.makeText(getApplicationContext(), "ACTION_ACL_CONNECTED" + device, Toast.LENGTH_LONG).show();
}
if (!Intent.ACTION_CAMERA_BUTTON.equals(action)) {
return;
}
KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event == null) {
return;
}
int action = event.getAction();
if (action == KeyEvent.ACTION_DOWN) {
// do something
Toast.makeText(context, "BUTTON PRESSED!", Toast.LENGTH_SHORT).show();
}
abortBroadcast();
}
};
Solution 3:
Using accessibility service, You can achieve auto-click.
Answer explained here, May be it's helpful to you !
Post a Comment for "How To Detect Click Event Of Connected Bluetooth Peripheral Device (selfie Stick)?"