Android - how to get callbacks from hardware buttons when pressed
978 3 2022-6-27
Uploading and Loding Picture ...(0/1)
o(^-^)o
djiuser_b9fA0wj643ey
lvl.1

Germany
Offline

I'm working on a camera app using Android Camera2 SDK which has button for start/stop recording, and a zoom functionality. I've integrated the DJI mobile SDK and I did the registration with the API key generated from the developer account. When I start the app, I receive a `REGISTRATION_SUCCESS` from `DJISDKManager.SDKManagerCallback()#onRegister()` and the Gimbal is connected through Bluetooth to the phone. I test the connectivity with handHeld.isConnected() which returns true.

Now the issue is, how can I intercept the hardware button press events from the Gimbal ?

I tried something like this, but it doesn't work. I couldn't find any documentation about how to receive callbacks when hardware buttons are pressed.

    HandHeld handHeld = (HandHeld) DJISDKManager.getInstance().getProduct();
        handHeld.getHandHeldController().setHardwareStateCallback(hardwareState -> {

            switch (hardwareState.getRecordAndShutterButtons()) {
                case IDLE: {
                    Log.e(TAG, "getRecordAndShutterButtons IDLE");
                    break;
                }
                case RECORD_CLICK: {
                    Log.e(TAG, "getRecordAndShutterButtons RECORD_CLICK");
                    break;
                }
                case SHUTTER_CLICK: {
                    Log.e(TAG, "getRecordAndShutterButtons SHUTTER_CLICK");
                    break;
                }
                case SHUTTER_LONG_CLICK: {
                    Log.e(TAG, "getRecordAndShutterButtons SHUTTER_LONG_CLICK");
                    break;
                }
                default: {
                    Log.e(TAG, "getRecordAndShutterButtons UNKNOWN");
                }
            }

            switch (hardwareState.getZoomState()) {
                case IDLE: {
                    Log.e(TAG, "getZoomState IDLE");
                    break;
                }
                case ZOOM_IN: {
                    Log.e(TAG, "getZoomState ZOOM_IN");
                    break;
                }
                case ZOOM_OUT: {
                    Log.e(TAG, "getZoomState ZOOM_OUT");
                    break;
                }
                default: {
                    Log.e(TAG, "getTriggerButton UNKNOWN");
                }
            }
        });

I tested hardwareState.getStickVerticalDirection() and hardwareState.getStickHorizontalDirection(), by moving the joystick analog and I get approximately the correct values (left/right/up/down)
but all other functions like hardwareState.getZoomState() or hardwareState.getRecordAndShutterButtons() they always return IDLE state. (when I press the record button, for some reason it increases the audio of the phone, and the volume seek bar appears, its like Im pressing the volume button)

These are some logs from handHeld.getHandHeldController().setHardwareStateCallback() that I receive randomly without pressing any button:

/com.dji.sdk.sample E/Camera2: getRecordAndShutterButtons IDLE
/com.dji.sdk.sample E/
Camera2: getZoomState IDLE
/com.dji.sdk.sample E/
Camera2: getTriggerButton IDLE
/com.dji.sdk.sample E/
Camera2: getModeButton IDLE
/com.dji.sdk.sample E/
Camera2: getRecordAndShutterButtons IDLE
/com.dji.sdk.sample E/
Camera2: getZoomState IDLE
/com.dji.sdk.sample E/
Camera2: getTriggerButton IDLE
/com.dji.sdk.sample E/
Camera2: getModeButton IDLE
/com.dji.sdk.sample E/
Camera2: getRecordAndShutterButtons IDLE
/com.dji.sdk.sample E/
Camera2: getZoomState IDLE
/com.dji.sdk.sample E/
Camera2: getTriggerButton IDLE
/com.dji.sdk.sample E/
Camera2: getModeButton IDLE

The model name is: OM5-602S46
Im using the Sample code app to test these hardware buttons callbacks.


It would be great that someone could help me on this.





2022-6-27
Use props
DAFlys
Captain
Flight distance : 312090263 ft
  • >>>
United Kingdom
Offline

Hi! You might be better off posting your question in the 'Developer' section of this forum.  That is way more active.    -   From https://developer.dji.com you can click Forum to access it or a direct link to it is - https://forum.dji.com/forum-139-1.html?from=developer
2022-6-27
Use props
djiuser_b9fA0wj643ey
lvl.1

Germany
Offline

Ok, thank you!
2022-6-27
Use props
DJI Stephen
DJI team
Offline

Hello there. Good day and thank you for giving out these information. For us to be able to assist you further with regards to this matter, please contact our DJI Development team at the link provided above by DAFlys on post #2. Thank you.
2022-6-28
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules