Android Question Byte array as Object for RunMethod

SteveTerrell

Active Member
Licensed User
The Bluetooth setPin method is defined as

public boolean setPin (byte[] pin)

RunMethod for "setPin" requires an Object so the parameter cannot be a byte array
i.e.
B4A version 4.30
Parsing code. 0.30
Compiling code. Error
Error compiling program.
Error description: Cannot cast type: {Type=Byte,Rank=1, RemoteObject=True} to: {Type=Object,Rank=1, RemoteObject=True}
Occurred on line: 617
If job.RunMethod("setPin", Array As Byte(pinBytes)) Then
Word: )

Is this the correct way to turn an array of bytes into an object?

B4X:
' Note    Dim job As JavaObject - then set to bluetooth device
   
    Dim pinBytes() As  Byte = Array As Byte(0x31,0x32,0x33,0x34)

    If job.RunMethod("setPin", Array As Object(pinBytes)) Then
        Log("set pin returned true")
    Else
        Log("set pin returned false ")
    End If
This code does run without an exception but always returns false!
 
Top