Use Programmable Keys

27 Jun 2024

You can make use of the Archer 4's two programmable keys as you develop custom apps. The keys are located on either side of the phone. 

Add an Action

To add an action to the list that appears from Settings > Programmable Keys,

  1. Add the line to the AndroidManifest.xml to create an entry in the programmable key list.

    <meta-data android:name = “meta_info_macro_key” android:value = “true”/>

  2. Add the following line to the AndroidManifest.xml to define what the entry should be called.

    <meta-data android:name = “meta_info_macro_key_title” android:resource = “@string/yourtitle”/>

    We recommend giving the string resource an action e.g. Scan, Capture Image, Lock GNSS.

Receive the Action 

  1. Create a class and extends BroadcastReceiver and Override onReceive method for the given custom intent

    public class MyBroadcastReceiver extends BroadcastReceiver {
        public static final String CUSTOM_ACTION = "com.action.borqs.progkey";

        @Override
        public void onReceive(Context context, Intent intent) {
            if (CUSTOM_ACTION.equals(intent.getAction())) {
                // Extract data from the intent
                // Handle the broadcast and data as needed
            }
            // TODO: This method is called when the BroadcastReceiver is receiving
            // an Intent broadcast.
            Toast.makeText(context,"Broadcast message is received",Toast.LENGTH_LONG).show();
        }
    }

  2. Dynamically register the BroadcastReceiver on “onCreate" method

     

    onCreate() {

        IntentFilter intentFilter =new IntentFilter(CUSTOM_ACTION);
        MyBroadcastReceiver mybroadcastreceiver = new MyBroadcastReceiver();
        registerReceiver(mybroadcastreceiver,intentFilter);
    }

     

If you need to know which of the keys was pressed to initiate the inclusion of the string resource as part of extra in the broadcast to your application, it can be extracted as

 +            String data = intent.getStringExtra("key");

You can download the following patch files to consult as a reference.

Reference patch 1

Reference patch 2