Android Question Barcode reader broadcast receiver

vdudukov

Member
Licensed User
Longtime User
Hi.

I am trying to communicate with barcode scanner integrated in PDA. So I found all development SDK for this scanner, but i dont know how to implement this.

What i need, is not keyboard emulation, but serial input,

Here is BARCODE SDK Manual.

I found about BROADCAST RECEIVER, and tried to implement,but without success.

Can somebody help please ?

Thanks!
 

vdudukov

Member
Licensed User
Longtime User
Hello.

I have another barcode reader and i got SDK, but i dont know how to get broadcast.

Java code:

package com.wpx.barcode.broadcast.activity;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

private static final String BARCODE_ACTION = "com.barcode.sendBroadcast";
private static final String BARCODE_PARAM = "BARCODE";

private TextView tv_barcode,tv_count;

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_barcode = (TextView)findViewById(R.id.tv_barcoce);
tv_count = (TextView)findViewById(R.id.tv_count);
}

@override
protected void onResume() {
// TODO Auto-generated method stubIntentFilter intentFilter = new IntentFilter(BARCODE_ACTION);
registerReceiver(barcodeBroadcastReceiver, intentFilter);
super.onResume();
}

@override
protected void onDestroy() {
// TODO Auto-generated method stubunregisterReceiver(barcodeBroadcastReceiver);
super.onDestroy();
}

int count = 0;
private BroadcastReceiver barcodeBroadcastReceiver = new BroadcastReceiver() {

@override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stubString action = intent.getAction();
if(BARCODE_ACTION.equals(action)){
String barcode = intent.getStringExtra(BARCODE_PARAM);
tv_barcode.setText(barcode);
tv_count.setText(String.valueOf(count++));
}
}
};
}
 
Upvote 0

vdudukov

Member
Licensed User
Longtime User
Found solution !

B4X:
Sub Service_Start (StartingIntent As Intent)


    Broadcast.SetPriority(2147483647)
    Broadcast.registerReceiver("com.barcode.sendBroadcast") 

End Sub

Sub Service_Destroy

End Sub

Sub BroadcastReceiver_OnReceive (Action As String, Extras As Object)
    Dim i As Intent = Extras
    Log(i.GetExtra("BARCODE"))
End Sub
 
Last edited:
Upvote 0
Top