Search code examples
javaandroidbluetoothcameraaccessibility

How to take picture in camera app programatically using accessibility service via Bluetooth BLE device?


I have Bluetooth (BLE) device where when I click button I want to perform action to capture photo or video in default camera app.

There are many Bluetooth devices (mostly from China) which "remotely take photo" when you are in default camera application with a single click of a button.

I searched the internet for the past month and I cou'dn't find a way how to perform the action to "click" on button in the camera app.

There are lots of tutorials how to do it via increasing volume up or down to perform capture image, but it does not work because you need special system permission to perform it via AudioManager.FLAG_FROM_KEY, but for that you need rooted device.

Another tutorial showed how to find the "button" via accessibilityEvent and find in currently opened application (camera app) text "Take photo" and perform a click action. This does not work, because many default application now don't have hidden text/label to the button.

Does anyone have any idea where to start looking or experience?


Example code:

MyAccessibilityService.java

public class MyAccessibilityService extends android.accessibilityservice.AccessibilityService
{
    public static AccessibilityService getInstance() {
        return this;
    }

    public void takePhoto() {
        // How to take photo ?
    }

    // ...

RandomClassWhereWeCallTheTakePhotoMethodFrom.java

public void onSingleClick() {
    myAccessibilityService = MyAccessibilityService.getInstance();
    myAccessibilityService.takePhoto();
}

What I mean by clicking on "button" in the camera app:
phone


Solution

  • These "chinese" triggers all use HID over GATT to simulate a volume button press, i.e. like a Bluetooth keyboard. That way you can pair it directly in the System settings. No app needed.