HaO 2019-04-08: Aim of this page is to show the translation of Java code to AndroWish borg broadcast... I have no idea about Java. This page may be evident to Java/Android insiders. For me, it was 3 days fiddelling and 2 E-Mails from Christian (thanks).
The application was to receive Barcode data from a Honeywell EDA50k0 with Android 7.1.1. The bar code scanner is activated by a scan button and returns data to the application on a succesful decode.
The first functionality is to send a broadcast.
The Java code is as follows:
private static final String ACTION_CLAIM_SCANNER = "com.honeywell.aidc.action.ACTION_CLAIM_SCANNER"; private static final String EXTRA_PROFILE = "com.honeywell.aidc.extra.EXTRA_PROFILE"; private static final String EXTRA_PROPERTIES = "com.honeywell.aidc.extra.EXTRA_PROPERTIES"; private static final String ACTION_BARCODE_DATA = "com.honeywell.sample.action.BARCODE_DATA"; ... private void claimScanner() { Bundle properties = new Bundle(); properties.putBoolean("DPR_DATA_INTENT", true); properties.putString("DPR_DATA_INTENT_ACTION", ACTION_BARCODE_DATA); sendBroadcast(new Intent(ACTION_CLAIM_SCANNER) .putExtra(EXTRA_PROFILE, "MyProfile1") .putExtra(EXTRA_PROPERTIES, properties) ); }
The important command is "sendBroadcast". The corresponding TCL borg command is:
borg broadcast send action ?uri type categories arguments?
with the following parameters:
The argument is documented within the documentation of "borg activity" as follows:
arguments are key-value pairs where the values are mapped to Java strings by default. If the key is a 2-element list made up of a data type indicator (int, byte, short, char, long, float, double, Uri) followed by the key, the value is converted to that data type. See below for some examples of this command.
Within Java, this is the part of the "sendBroadcast" with ".putsExtra(argkey, argval)".
If "argVal" is not of Java types string, int, byte, short, char, long, float, double, Uri, it is not supported.
We have the following commands in the example:
private static final String EXTRA_PROFILE = "com.honeywell.aidc.extra.EXTRA_PROFILE"; ... .putExtra(EXTRA_PROFILE, "MyProfile1")
In this case, "MyProfile1" is a string. This may be implemented by an argument list of: "com.honeywell.aidc.extra.EXTRA_PROFILE" "MyProfile1".
private static final String EXTRA_PROPERTIES = "com.honeywell.aidc.extra.EXTRA_PROPERTIES"; private static final String ACTION_BARCODE_DATA = "com.honeywell.sample.action.BARCODE_DATA"; ... Bundle properties = new Bundle(); properties.putBoolean("DPR_DATA_INTENT", true); properties.putString("DPR_DATA_INTENT_ACTION", ACTION_BARCODE_DATA); ... .putExtra(EXTRA_PROPERTIES, properties)
The variable "properties" is of type "Bundle". This is not supported by AndroWish. Christian sees the possibility to directly include Java with TCLJBlend requiring the current trunk.
I decided not to include this parameter and work around it by configuration.
The final broadcast call is as follows:
borg broadcast send com.honeywell.aidc.action.ACTION_CLAIM_SCANNER {} {} {}\ [list com.honeywell.aidc.extra.EXTRA_PROFILE MyProfile1]
The following message gets written to the system log:
04-08 10:07:40.671 2877 2877 I DCS-IntentApi: onReceive, action: com.honeywell.aidc.action.ACTION_CLAIM_SCANNER ... 04-08 10:07:40.674 2877 2877 I DCS-IntentApi: setProfile: MyProfile1
When the broadcast is executed (data scanned), the following message is written to the Android log:
04-08 10:14:16.154 1698 2860 E ActivityManager: Sending non-protected broadcast com.honeywell.sample.action.BARCODE_DATA from system 2881:...
Note: The action name "com.honeywell.sample.action.BARCODE_DATA" was set manually in the properties of profile "MyProfile1".
The second function is to receive data from a broadcast sent by the bar code scanner, e.g. the bar code data when scanned. It is composed of two parts, the setup and the called routine. Both are present in Java and TCL.
The java code is as follows:
private static final String ACTION_BARCODE_DATA = "com.honeywell.sample.action.BARCODE_DATA"; @Override protected void onResume() { super.onResume(); registerReceiver(barcodeDataReceiver, new IntentFilter(ACTION_BARCODE_DATA)); }
The key command within Java is "registerReceiver(barcodeDataReceiver, new IntentFilter(ACTION_BARCODE_DATA));". The intent name and handling function is passed.
The corresponding AndroWish borg command is:
borg broadcast register action cmd
The parameters are:
In this case, the command is:
borg broadcast register com.honeywell.sample.action.BARCODE_DATA callback
When registered, the Android log contains this line:
04-08 10:14:16.171 9041 9041 V AndroWish: nativeBroadcastCallback: -1,com.honeywell.aidc.action.ACTION_CLAIM_SCANNER,null,null,null,[Ljava.lang.String;@22cd7a8
The java code is as follows:
private BroadcastReceiver barcodeDataReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (ACTION_BARCODE_DATA.equals(intent.getAction())) { int version = intent.getIntExtra("version", 0); String data = intent.getStringExtra("data"); ... (some additional values here) } } };
The TCL callback function is called with the following parameters:
proc callback {CodeIn ActionIn URIIn TypeIn CategoryIn lDataIn} { ... }
In my case, the parameters are as follows:
TCL looks so easy compared to Java...
When Android stops the application, the scanner claim should be stopped and also the bradcast notification:
borg broadcast unregister com.honeywell.sample.action.BARCODE_DATA
After a discussion on clt "Re: Androwish: when fires <<Terminating>> virtual event" started 2019-04-10:
The virtual event "<<DidEnterForeground>>" is called when the application is actively put into foreground but not on startup. Thus, scanning is activated on program startup and on virtual event "<<DidEnterForeground>>".
Scanning is stopped on virtual event "<<WillEnterBackground>>".
bind . <<DidEnterForeground>> +ScannerRegister bind . <<WillEnterBackground>> +ScannerUnregister
The new bindings are added with "+" so other modules using this event are not disturbed. I may imagine that there are a lot...
I called the function on bind: remove one command to remove the bindings on module unload.