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(savedInstanceState);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
this.registerReceiver(mReceiver, filter);
}
//The BroadcastReceiver that listens for bluetooth broadcasts
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(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();
}
}
};
My question is how I can detect button press/click event of this connected peripheral device?
Help in form of code snippet/tutorial/comments is highly appreciable. Thanks!!!
EDIT:
When I press button of Selfie stick Volume + button listen to the event
I found the answer. It was very simple. Just override
onKeyDown()
method of Activity.Here
keyCode
is the event name returned.Using accessibility service, You can achieve auto-click.
Answer explained here, May be it's helpful to you !
I have made slight modifications in your code. Please see if its helpful
//The BroadcastReceiver that listens for bluetooth broadcasts