Android Question laser bar code intent

werner_Fourie

Member
Licensed User
Hi all..

I'm stuck with this..

I need to get the bar code from the internal bar code reader with this intent..

Broadcast name is > com.scanner.broadcast
key > data

I have never worked with intents and I just need a little help please..

Thanking You in advance..
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Broadcast name is > com.scanner.broadcast
key > data
Is this the actual documentation?

Start with:
B4X:
'add a service named Service1
AddReceiverText(Service1,
<intent-filter >
   <action android:name="com.scanner.broadcast" />
</intent-filter>
)
Though the action doesn't look correct.
 
Upvote 0

werner_Fourie

Member
Licensed User
Is this the actual documentation?

Start with:
B4X:
'add a service named Service1
AddReceiverText(Service1,
<intent-filter >
   <action android:name="com.scanner.broadcast" />
</intent-filter>
)
Though the action doesn't look correct.
Hi

Thanks for the reply..
Yes that is all they show in there intent section..
I have done what You said and when I scan a bar code there seems to be a response but i don't know how to capture the bar code data..

When I scan the bar code i get this response

** Receiver (service1) OnReceive **
** Service (service1) Start **
.....com.scanner.broadcast

[Sub Service_Start (StartingIntent As Intent)
Log("....." & StartingIntent.Action)
Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub]

how do I actually get the data..?

I did search the forum but I don't understand intents yet..

Thanks

Werner
 
Upvote 0

werner_Fourie

Member
Licensed User
Please use [code]code here...[/code] tags when posting code.


Good.

Post the output of:
B4X:
Log(StartingIntent)
Log(StartingIntext.ExtrasToString)
Ok
It starts to make sense..

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (service1) Create ***
** Service (service1) Start **
no extras
** Receiver (service1) OnReceive **
** Service (service1) Start **
Bundle[{dataBytes=[B@9265837, barcodeStringData=� E����PGH�����Wt ��dv�o�(���"z�O>ztMCd"%dqo���C9������n�XS��9m4����LƎ��sA㗚��U��=�J֬�sq��'�R�������q
X�7F[%У^�a|GS�-�T
���3Ǝ��ykΰP��B|&��o�{�u�>+>ȕ^a�=D��Q�������r�[���t����-�Bo;��y��|�?n��#m�#pa�
3�\�#���d����*�k.x�
`/%�x���۾�]-�RX�"�8OA?ȃ�P(�еm�Q�-q,�~�!���'��=�Pa�hk���{hc� �u�,���B�Ce�'���JC:8�?*9��|/ES<Qׇ�`O��5���Q��VU
��g�F|}��R���僛�����$�[���i4�9��,yl���k.�?����0�!9��F�G� �l�.��J��2�=\��E�t�E}�gX��8ύ��8����,��c̲w�6��I��p�K�a�~v��R?�@�x�
99��3w�Jm��������$�"W�B��l.pM����g� ��Ƽ�{l���{�䔿M&֣�����T�߷�`czr�3#?�'Q1����tY�U~��d�A;���a��K�7h v
���S����LA0��(tp
L����Y��
卾zxyڀ )�J#���"�R[Z�jL8L�"���R�� U, data=� E����PGH������Wt ��dv�o�(���"z�O>ztMCd"%dqo���C9������n�XS��9m4����L����sA������U��=�J���sq��'�R�������q
X�7F[%��^�a|GS�-�T
���3����yk��P��B|&��o�{�u�>+>��^a�=D��Q��������r�[���t�����-�Bo;��y��|�?n��#m�#pa�
3�\�#���d����*�k.x�
`/%�x������]-�RX�"�8OA?���P(���m�Q��-q,�~�!���'���=�Pa�hk���{hc� �u�,���B�Ce�'���JC:8�?*9��|/ES<Q���`O��5���Q��VU
��g�F|}��R�����������$�[���i4�9��,yl���k.�?����0�!9��F�G� �l�.��J��2�=\��E�t�E}�gX����8����8����,��c��w�6��I��p�K�a�~v��R?�@�x�
99��3w�Jm�����������$�"W�B��l.pM����g� �����{l���{����M&�������T����`czr�3#?�'Q1����tY�U~��d�A;���a��K�7h v
���S����LA0��(tp
L����Y��
���zxy�� )�J#���"�R[Z�jL8L��"���R�� U
, resultStatus=success, barcodeDecodeTime=136, SCAN_STATE=success, DecodeTime=136, barcodeResultCode=1, barcodeByteData=[B@5be81a4, barcodeCode=11, barcodeNAME=PDF417, CODE_TYPE=PDF417}]


so am I correct when I say the barcode data will be in DD=StartingIntent.GetExtra("barcodeStringData")

Thanks for the response
 
Upvote 0

werner_Fourie

Member
Licensed User
The encoding looks wrong.

Maybe you need to get the array of bytes from dataBytes and convert it to string using BytesToString and the correct encoding.
Hi Errol

Thank You for the response

I'm getting a better understanding of what is happening..

The decoding is wrong it should be "ISO8859_1"

This is what i get back now from from "dataBytes"..

it changes on every scan of the same bar code..Now I'm even more confused..

do I need to use BytesBuilder to get to the result?


*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (service1) Create ***
** Service (service1) Start **
** Receiver (service1) OnReceive **
** Service (service1) Start **
[B@677efb2
** Receiver (service1) OnReceive **
** Service (service1) Start **
[B@1c57b03
** Receiver (service1) OnReceive **
** Service (service1) Start **
[B@3e27a80
** Receiver (service1) OnReceive **
** Service (service1) Start **
[B@7c158b9


regards

werner
 
Upvote 0

werner_Fourie

Member
Licensed User
Hi Errol

Thank You for the response

I'm getting a better understanding of what is happening..

The decoding is wrong it should be "ISO8859_1"

This is what i get back now from from "dataBytes"..

it changes on every scan of the same bar code..Now I'm even more confused..

do I need to use BytesBuilder to get to the result?


*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (service1) Create ***
** Service (service1) Start **
** Receiver (service1) OnReceive **
** Service (service1) Start **
[B@677efb2
** Receiver (service1) OnReceive **
** Service (service1) Start **
[B@1c57b03
** Receiver (service1) OnReceive **
** Service (service1) Start **
[B@3e27a80
** Receiver (service1) OnReceive **
** Service (service1) Start **
[B@7c158b9


regards

werner
Hi Errol

Thank You for taking the time with my problem..
I managed to resolve it..

[Dim content() As Byte = StartingIntent.GetExtra("dataBytes")
strBuff = con.StringFromBytes(content,"ISO8859_1")
Log(strBuff)]


This did the trick...

Regards

Werner
 
Upvote 0

Setlodi

Member
Hi Werner
I was referred to you by Johan Schoeman. I'm using his SA License scanning B4J project and I've encountered an issue which he thinks you might help me to sort out. I'm using a Sunmi L2S hand held device with a native scanner and app. When I read the SADL barcode, my string is different from what Johan is getting from his scanner and therefore it cannot be properly converted to Hex before decrypting using the public keys. Although at a quick glance it looks similar, my string is a bit longer. Do you have any idea how I can solve this? I have tried different scanner settings (UTF-8, ISO 8859-1, Windows 1256 etc,)

Your assistance will be greatly appreciated.

Johan's string:

E����JNÒsÑÿ!7nܵÈê'ß7¢ÿáÀük-Sc§s4ÿµ#6ÊN¿gµêðWsWà'cuz^¿;ýÐW-nÞýöîæ4wY)^þ«"í2ìÆ,<P8LKùà½äF`$2ÿÍ|BîÂt]·9©onkq©3çX
×ü<ª!¤&·��âí}cz}[q@>8Ñàt¨;åy¢`ãRÅÂEË¡ ÕdáÞKÒ/
\©ð&Aìcaèü¸Ä<:¼"CÃÕ¿ÐDª/õL®ZæÄÚÍæÑü`¦"mLMÝmrAdk¨±ì:fð·!º®bó8¡y[£%.3ý³×Ð> ܪ 2¸wä$¹òz+Æή
P0b£´
F^y¾Ø#é SyúkÛ«uôHEyµþpÑÈÄ@<wæ_Ì×i)"ó꺼ð?Úr¥¬gñJö¾@îÐá 8H`J`¶d÷óqPǸu¢gg4õúVÌs7íµÉäVhL£¸gLè¶5ä1}&Å}¿QìüïÝ·+ùÏåzVÄCóÁ%¨§8ªÜ-JX¿ÚljpÆ<ض#åT5ýK§DÞNu;® Å÷¦LcgVñHL
GñxÊYÊgî¾Ë¹üYSðP!1K#Ò|J}v©³°ZÓÒTB³eÉ.t~¼ñÀñ~h©|ü·ºÿ}`½}³k
~@K±ËÍ3·Ð×£«^)fö§ óñ¥Áx·O¯*U˵p°hD*úûéÿb
¬fÇO¸Kîß×á²B5Ûk]
Ú±?ÚtÌàìʧâ#:9© ÓUÖëÛ
Òø®EÅïi|÷q·

My string:

› E H¸k

Ä W¾NÁÕ £ J»õ$lÖ ¶ o 0™(Î÷=雼4qh?sx‡+yÐÍx9‚ÉK¹ î Å:<2z°J †ÅiQ}ô4åü€vë³ç+¬º Tj[ qƤ^Í&dž‡ëbܽÈ0Î>-º›0L×á{¢bâʇ¦JTÖë… -x,ßñy

ÜÝtƬO
ö ÈÒuaç ³W gÓ UseÎä

 ý[‡càÜÆÁeêÏQ =ˆ•îÃk*P¡¬ 5°{µ½¤ ]ëYsŒRŸ·ŸaÌÎBà ‘ ” ËQa¤Ð3!ð ̺°ý È•³á-Ð w aŸoÉ ®l/vài Än;ßSþÚ:L~ª=§=‚qvÚ¡š Qldz9KwN‰P ©‡ RCÕ Yb ø¯P ^{çÿïæ á=sþêSƒ`[âþ»Ú½EŽ½ AâÐüó0 y ¢¹ü .Fjª Ùb¥æt ¥ .¡©R B¼| 3¾Î“ñ3ýj uª¹…¨¹gY™ö

ËÂ’Ô×âf £ Æ · ê [ yÊ ´¨ÿF* PDnœ® ›Ó¶" 0Ëð7«É4ÍMÿsØ

S$üöÅ

<€éíÃ0. ˆOÓ© TWØÓgóÈ ó¨ `EöÚÔ— —ãòqw£ÞÅ Ø! Ó²Ú<µôAì ë ªôÝA ¸–¨m{ž – ¤àªh² î O¾ÁXƒxÄ r… EèNU@ª lËt7 Ô{ˆ<ˆ<= ‰z–¸6´ —óÕ¯¿ w -nDÚ@P\\Y;( ™õ þ#»…ö¨ f€™›Þ |@‹ ª .` |è9Å!ÏR‹Aä ,ˆ 'V ì‹ ´O Ëg\\4£ !r)¦' æ ë{i§þ ç» '¯ ”>5ÚáÐÈ eiKÞ\\ÖŸã‘ "ñÑ Ä FéDek<‹Íßàc ÷ ÇX

‘õ; mÜû%Ùg½eåçr
 
Upvote 0

werner_Fourie

Member
Licensed User
Hi How are You

It was a long time a go but I managed to get it working..

Cant remember the details but have a look in the attached code..
Just get rid of what You don't need in my code and it should work..
Remember to make sure that the barcode reader is in intent mode..

AddReceiverText(Service1,
<intent-filter >
<action android:name="com.scanner.broadcast" />
</intent-filter>
)

The intent name in the scanner should be "dataBytes"

Hope You get it working..

Send me Your email address and I will send You the code..

It is too large to attach here..
 
Upvote 0

Setlodi

Member
Hi Werner

I hope this finds you well. Thank you once more for the code.

I'm isolating the license canning part of the code and I'm getting the following :

B4XMainPage - 82: Unknown type: udpsocket<br />Are you missing a library reference?
B4XMainPage - 76: Unknown type: udpsocket<br />Are you missing a library reference?
B4XMainPage - 73: Unknown type: toggle<br />Are you missing a library reference?
B4XMainPage - 34: Unknown type: stringutils<br />Are you missing a library reference?
B4XMainPage - 30: Unknown type: byteconverter<br />Are you missing a library reference?
B4XMainPage - 334: Unknown type: byteconverter<br />Are you missing a library reference?
B4XMainPage - 329: Unknown type: byteconverter

I managed to find ByteConverter and StringUtils but I've looked everywhere and can't find:
  • toggle
  • udpsocket
Any idea where I can get them?

Thank you for your assistance.
 
Upvote 0

Setlodi

Member
Hi ..

I will send You a list of all my external libs..
Just go trough them..
It should be straight foreword..
Check Your mail ..
Hi Werner

Thank you so much for the additional libraries. All library errors have been sorted. I'm receiving this error, which I will work on today:

B4A Version: 11.80
Parsing code. Error
Specified argument was out of the range of valid values.
Parameter name: index


I will keep you in the loop on my progress.

Setlodi
 
Upvote 0

Setlodi

Member
Hi Werner

I hope you are well. I managed to finally get all the required libraries and compile the code. Now I'm stuck on connecting the internal scanner to the application. I have received code from the manufacturer to include in my app but I'm not sure how to proceed from here.

Here's the code from the device manufacturer:

Connect Service (AIDL):
private static ServiceConnection conn = new ServiceConnection () {

@Override

public void onServiceConnected(ComponentName name,IBinder service) {
scanInterface = IScanInterface.Stub.asInterface(service);
Log.i(" setting", "Scanner Service Connected!");

}

@Override

public void onServiceDisconnected(ComponentName name ) {
Log.e(" setting", "Scanner Service Disconnected!");
scanInterface = null;

}

};

public void bindScannerService() {

Intent intent = new Intent
intent.setPackage("com.sunmi.scanner");
intent.setAction("com.sunmi.scanner.IScanInterface");
bindService(intent, conn, Service.BIND_AUTO_CREATE);
}

And now the broadcast section

Broadcast introduce:
private static final String ACTION_DATA_CODE_RECEIVED = "com.sunmi.scanner.ACTION_DATA_CODE_RECEIVED";
private static final String DATA = "data";
private static final String SOURCE = "source_byte";
private BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override public void onReceive(Context context, Intent intent) {
        String code = intent.getStringExtra(DATA);
        String arr = intent.getByteArrayExtra(SOURCE);
        if (code != null && !code.isEmpty()) {
            mCode.setText(code);
        }
    }
};
private void registerReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_DATA_CODE_RECEIVED);
    registerReceiver(receiver, filter);
}
 
Upvote 0

werner_Fourie

Member
Licensed User
Hi Werner

I hope you are well. I managed to finally get all the required libraries and compile the code. Now I'm stuck on connecting the internal scanner to the application. I have received code from the manufacturer to include in my app but I'm not sure how to proceed from here.

Here's the code from the device manufacturer:

Connect Service (AIDL):
private static ServiceConnection conn = new ServiceConnection () {

@Override

public void onServiceConnected(ComponentName name,IBinder service) {
scanInterface = IScanInterface.Stub.asInterface(service);
Log.i(" setting", "Scanner Service Connected!");

}

@Override

public void onServiceDisconnected(ComponentName name ) {
Log.e(" setting", "Scanner Service Disconnected!");
scanInterface = null;

}

};

public void bindScannerService() {

Intent intent = new Intent
intent.setPackage("com.sunmi.scanner");
intent.setAction("com.sunmi.scanner.IScanInterface");
bindService(intent, conn, Service.BIND_AUTO_CREATE);
}

And now the broadcast section

Broadcast introduce:
private static final String ACTION_DATA_CODE_RECEIVED = "com.sunmi.scanner.ACTION_DATA_CODE_RECEIVED";
private static final String DATA = "data";
private static final String SOURCE = "source_byte";
private BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override public void onReceive(Context context, Intent intent) {
        String code = intent.getStringExtra(DATA);
        String arr = intent.getByteArrayExtra(SOURCE);
        if (code != null && !code.isEmpty()) {
            mCode.setText(code);
        }
    }
};
private void registerReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_DATA_CODE_RECEIVED);
    registerReceiver(receiver, filter);
}
Hi

Look at this part in the manifest..

AddReceiverText(Service1,
<intent-filter >
<action android:name="com.scanner.broadcast" />
</intent-filter>
)

I think in Your case it should be "com.sunmi.scanner"

Just try it...
 
Upvote 0

Setlodi

Member
Hi Werner

Thanks for your response. I did change that part in the manifest but I still get nothing. The scanner beeps when I try to scan but nothing appears in the driver or vehicle section of the app. I seems like the scanner is not communicating with the app.
 
Upvote 0

werner_Fourie

Member
Licensed User
Hi Werner

Thanks for your response. I did change that part in the manifest but I still get nothing. The scanner beeps when I try to scan but nothing appears in the driver or vehicle section of the app. I seems like the scanner is not communicating with the app.
Run the log on this line and see if You get anything from the reader

Intent_StrBuff_Veh = StartingIntent.GetExtra("barcodeStringData")
Log(Intent_StrBuff_Veh)
 
Upvote 0
Top