Working with Android on a Barcodescanner with Datawedge and get Data with Intent:

Working with Android on a Barcodescanner with Datawedge and get Data with Intent:

To get that intent-receive working ...

1.) i'm using the broadcastreceiver from Baris Atalay:
brsatalay.blogspot.com.tr/2014/10/delphi-android-broadcast-receiver.html


2.) add following scripts to your formcreate:
myreceiver.RegisterReceive;
myreceiver.Add('org.mein.intent.name');


3.) create your onReceive event as follows:
procedure Tform1.myreceiverReceive(Context: JContext; Intent: JIntent);
begin
// use a Thread !! important
tThread.CreateAnonymousThread(procedure begin
internal_ReceiveIntent(Context, Intent);
end).start;
end;

procedure Tform1.internal_ReceiveIntent(Context: JContext; Intent: JIntent);
var
vInput:String;
begin
if ansisametext(JStringToString(intent.getAction), 'org.mein.intent.name') then begin
vInput:=JStringToString(intent.getStringExtra(StringToJString(DATAWEDGE_DATA_STRING)));
vInput:=trim(vInput);
// you have received something, go process it

end;
end;


4.) Now add only one additional line to your androidmanifest:
...
android:label="%activityLabel%"
android:configChanges="orientation|keyboard|keyboa rdHidden|screenSize"
android:launchMode="singleTask">

android:value="%libNameValue%" />


org.mein.intent.name" />



...


5.) Create a profile in Datawedge for your application as follows:
1. Select your application as connected app
2. Enable barcode-input checkbox
3. Enable msr checkbox
4. Enable Intent checkbox
4.1 Define your Intent-Aktion = org.mein.intent.name
4.2 leave Intent-Category EMPTY (!)
4.3 Select Send-Intent


Thats all. Now you have a app which can work i.e. on MC3200 from Motorola and can read the barcodes very fast! Another thing is, that you can also get i.e. commands with barcode and process them in your receive event. If you need to put the received barcode to a tEdit you can use something like this:

1.) var iControl:tControl, ikey:word; iKeyChar:char; iShift:tShiftState;

2.) iControl:=tControl(self.Focused.GetObject);
if iControl<>nil then begin
if iControl is tEdit then begin
tThread.synchronize(nil, procedure begin
tEdit(iControl).Text:=vInput;
if assigned(tEdit(iControl).OnKeyUp) then begin
iKey:=13;
iKeyChar:=#13;
tEdit(iControl).OnKeyUp(tEdit(iControl), iKey, iKeyChar, iShift);
end;
end);
end;
if iControl is tMemo then begin
tThread.synchronize(nil, procedure begin
tMemo(iControl).lines.add(vInput);
end);
end;
end;


Hope this helps other developers having same problems as I had with android and mc3200

Comments

  1. Yusuf Zorlu​ this is a nice way to implement this ! But I don't know how to make this working with scanwedge. I've opened an ticket at Honeywell support, asking them if scanwedge does support receiving broadcast messages...

    ReplyDelete
  2. Stéphane Wierzbicki if you get that working, inform us so we can update github for datawedge and scanwedge ;-)

    ReplyDelete

Post a Comment