Android Question Byte array as Object for RunMethod

Discussion in 'Android Questions' started by SteveTerrell, Feb 16, 2015.

  1. SteveTerrell

    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?

    Code:
    ' 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!
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Your code is correct (though you are not turning it into an object, you are adding it to an array of objects).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice