How to get java Message Handler Data in basic4android. Please Help

joazzz

Member
Licensed User
Longtime User
:sign0163:
How to get java Message Handler Data in basic4android. Please Help

PHP:
*****Example java)
package com.test;

import com.cardcompany.BluetoothCardReaderApi;
import android.os.Handler;
import android.os.Message;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
//import anywheresoftware.b4a.BA.Events;

@ShortName("BlueToothCreditCardTest")
@Permissions(values={"android.permission.BLUETOOTH_ADMIN", "android.permission.BLUETOOTH"})
@Version(1)
@DependsOn(values={"BluetoothCardReaderApi"})   //BluetoothCardReaderApi.jar 
//@Events(values={"catched(intWhatData As Int, BytRawData() as byte)"})

public class BlueToothCreditCardTest {
   
    BluetoothCardReaderApi MyCardDeviceApi = new BluetoothCardReaderApi();

    public String BlueToothConnectAndSetHandler(String StrMacAddress)
    {
        int intRet = MyCardDeviceApi.BlueConnect(StrMacAddress);
        if(intRet == 1)  //if Connected then Set Recieve Message Handler
        {
            MyCardDeviceApi.SetBlueToothHandler(MyBlueToHandler);
            return "OK";
        }
        else
        {
            return "Not OK";
        }
    }
   
    //BA ba;

    //Question: How to get java Message Handler Data (intWhatData, BytRawData) in basic4android
    //*********************************************************************
    //Bluetooth Recieve data Message Handler
    Handler MyBlueToHandler = new Handler() {
        public void handleMessage(Message MyMsg) {
            int intWhatData = MyMsg.what;
            byte[] BytRawData = (byte[])MyMsg.obj;

            //ba.raiseEvent(this, "carddata_catched", intWhatData, BytRawData);
            //(Error occurred: java.lang.NullPointerException Continue?)
        }
    };
    //*********************************************************************
}


*****BlueToothCreditCardTest.xml*****
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <doclet-version-NOT-library-version>1.02</doclet-version-NOT-library-version>
    <class>
        <name>com.test.BlueToothCreditCardTest</name>
        <shortname>BlueToothCreditCardTest</shortname>
        <owner>process</owner>
        <permission>android.permission.BLUETOOTH_ADMIN</permission>
        <permission>android.permission.BLUETOOTH</permission>
        <method>
            <name>BlueToothConnectAndSetHandler</name>
            <comment></comment>
            <returntype>java.lang.String</returntype>
            <parameter>
                <name>StrBlueToothCardDeviceMacAddress</name>
                <type>java.lang.String</type>
            </parameter>
        </method>
    </class>
    <version>1.0</version>
    <dependsOn>BluetoothCardReaderApi</dependsOn>
</root>


*****Basic4Android(Copy to Libraries :BlueToothCreditCardTest.jar .xml, BluetoothCardReaderApi.jar) and IDE Libs Check*****
Sub Globals
   Dim GblMyCard As BlueToothCreditCardTest
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Layout1")
End Sub

Sub Button1_Click
   Dim StrReturn As String
   StrReturn = GblMyCard.BlueToothConnectAndSetHandler("00:15:8B:58:83:0A")
   Msgbox(StrReturn,"Result") 'Result:OK   how to get handler data(intWhatData, BytRawData)
End Sub

'Sub carddata_catched (intWhatData as int, BytRawData() as byte)
'   Msgbox("in","") 'Not Response (Java Error: java.lang.NullPointerException Continue?)
'End Sub
'
'
 
Top