Android Question doubts about definition of java object

robertogv64

Member
Licensed User
Regards,

I hope someone can help me.

It is I am implementing a library that handles an api in java like the following example:

Java:
TemperatureData temperatureData = temperatureUtil.getDataAndBitmap(distances,true, new HotImageCallback.Stub() {
                           @Override
                           public void onTemperatureFail(String e) {
                               Log.i("getDataAndBitmap", "onTemperatureFail " + e);
                               showTip("Failed to get temperature:  " + e);
                           }

                           @Override
                           public void getTemperatureBimapData(final TemperatureBitmapData data) {
                               runOnUiThread(new Runnable() {
                                   @Override
                                   public void run() {
                                       image.setImageBitmap(data.getBitmap());
                                   }
                               });
                           }

                       });


The parameter defined as new HotImageCallback.Stub ()..... as B4A would be represented with a javaobject?
 

robertogv64

Member
Licensed User
Greetings Erel thanks for the observation.

I did the whole implementation in JavaObject but it indicates an error of "java.lang.RuntimeException: Method: getDataAndBitmap not matched"

The implementation carried out is as follows:
B4X:
Sub Globals
    Private temp As JavaObject
    Private callB As JavaObject
    Private temdata As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)
    temp = ThermalImageUtil ' incializa el metodo de captura
End Sub

Sub Activity_Resume

            temdata = TemperatureDataUtil
           
            callB = CallbackUtil_Temp
           
            Dim distance As Float = 50
           
            temdata = temp.RunMethod("getDataAndBitmap",Array As Object(distance,True, callB))
       
End Sub


Sub ThermalImageUtil As JavaObject
    Dim jo As JavaObject
    Return jo.InitializeNewInstance("com.common.thermalimage.ThermalImageUtil", Array(GetContext))
End Sub

Sub CallbackUtil_Temp As JavaObject
    Dim jo As JavaObject
    Return jo.InitializeStatic("com.common.thermalimage.HotImageCallback.Stub")
End Sub

Sub TemperatureDataUtil As JavaObject
    Dim jo As JavaObject
    Return jo.InitializeStatic("com.common.thermalimage.TemperatureData")
End Sub

Sub GetContext As JavaObject
    Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetFieldJO("processBA")
End Sub
 
Last edited:
Upvote 0

robertogv64

Member
Licensed User
I don't understand why you don't recognize it.

The definition of the class in java is the following:
B4X:
  public TemperatureData getDataAndBitmap(float distanceFromApp, boolean needRecordTemAuto, HotImageCallback callBack) {
    Log.i(TAG, "+ this.sdf.format(new Date()));
    if (!this.isConneted) {
      Log.i(TAG, ");
      try {
        if (callBack != null)
          callBack.onTemperatureFail("connect service fail,please restart your app or check the TemperatureService app is installed");
      } catch (Exception exception) {}
      return null;
    }
    if (this.devServ != null && this.devServ.asBinder().isBinderAlive())
      try {
        TemperatureData data = this.devServ.getDataAndBitmapByFix(distanceFromApp, needRecordTemAuto, callBack);
        Log.i(TAG, "+ this.sdf.format(new Date()));
        return data;
      } catch (RemoteException e) {
        e.printStackTrace();
      } 
    return null;
  }
 
Upvote 0
Top