Hello everyone, i am having a problem with inline java and javaobject. I have a co-developer who knows how to code in java, my problem is i don't know how to pass the code to b4a. i can't get the return value of the java code. below is the inline java code:
then my code
I hope someone can help me or teach me how to do it.
B4X:
#if java
import com.vanstone.appsdk.client.ISdkStatue;
import com.vanstone.trans.api.PrinterApi;
import com.vanstone.trans.api.SystemApi;
import com.vanstone.utils.CommonConvert;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
int pflag = 0;
Activity cActivity;
public void setTestContext(Activity activity) {
cActivity = activity;
}
public void initialized_api(Activity activity) {
/*
new Thread() {
public void run() {
SystemApi.SystemInit_Api(0, CommonConvert.StringToBytes(getCurAppDir() + "/" + "\0"), activity, new ISdkStatue() {
@Override
public void sdkInitSuccessed() {
pflag = 1;
}
@Override
public void sdkInitFailed() {
pflag = 0;
}
});
}
}.start();*/
SystemApi.SystemInit_Api(0, CommonConvert.StringToBytes(getCurAppDir() + "/" + "\0"), activity, new ISdkStatue() {
@Override
public void sdkInitSuccessed() {
pflag = 1;
}
@Override
public void sdkInitFailed() {
pflag = 0;
}
});
}
public String getCurAppDir() {
String CurAppDir = this.getApplicationContext().getFilesDir().getAbsolutePath();
return CurAppDir;
}
public Activity getCurrentContext() {
return cActivity;
}
public int getFlag() {
return pflag;
}
public void PrtCardInfo() {
PrinterApi.PrnClrBuff_Api();
PrinterApi.PrnFontSet_Api(32, 32, 0);
PrinterApi.PrnSetGray_Api(15);
PrinterApi.PrnLineSpaceSet_Api((short) 5, 0);
PrinterApi.PrnStr_Api(" POS Receipt");
PrinterApi.PrnFontSet_Api(24, 24, 0);
PrinterApi.PrnStr_Api(" CARDHOLDER COPY");
PrinterApi.PrnStr_Api("--------------------------------");
PrinterApi.PrnStr_Api("MERCHANT NAME:");
PrinterApi.PrnStr_Api("CARREFOUR");
PrinterApi.PrnStr_Api("MERCHANT NO.: 941160147848170");
PrinterApi.PrnStr_Api("120401124594");
PrinterApi.PrnStr_Api("TERMINAL NO.: ");
PrinterApi.PrnStr_Api("TRANS TYPE.: ");
PrinterApi.PrnFontSet_Api(32, 32, 0);
PrinterApi.PrnStr_Api("Sale");
PrinterApi.PrnFontSet_Api(24, 24, 0);
PrinterApi.PrnStr_Api("PAYMENT TYPE.: ");
PrinterApi.PrnStr_Api("CARDHOLDER SIGNATURE:\n\n\n\n");
PrinterApi.PrnStr_Api("--------------------------------");
PrinterApi.PrnStr_Api("I accept this trade and allow it on my account");
PrinterApi.PrnStr_Api("----------x------------x-------");
PrinterApi.PrnStr_Api("\n\n");
PrinterApi.printAddBarCode_Api(1, 300, 120, "12345");
PrinterApi.PrnStr_Api("\n\n");
PrinterApi.printAddQrCode_Api(1, 300, "www.szfptech.com");
PrinterApi.PrnStr_Api("\n\n\n\n");
PrintData();
}
public static int PrintData() {
int ret;
String Buf = null;
while (true) {
ret = PrinterApi.PrnStart_Api();
Log.d("aabb", "PrnStart_Api:" + ret);
if (ret == 2) {
Buf = "Return:" + ret + " paper is not enough";
} else if (ret == 3) {
Buf = "Return:" + ret + " too hot";
} else if (ret == 4) {
Buf = "Return:" + ret + " PLS put it back\nPress any key to reprint";
} else if (ret == 0) {
return 0;
}
return -1;
}
}
#End If
B4X:
Sub GetActivity As Object
Dim R As Reflector
Return R.GetActivity
End Sub
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Private NativeMe As JavaObject
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
NativeMe.InitializeContext
NativeMe.RunMethod("initialized_api", Array(GetActivity))
End Sub
I hope someone can help me or teach me how to do it.