GetExtra

leongcc

Member
Licensed User
Longtime User
I use the same key for HasExtra() and GetExtra().
HasExtra() retuens True but GetExtra() returns null, that is MacObject is null.
Any advice?


B4X:
Sub BroadCastReceiver_OnReceive (Action As String,  i As  Object)   
    Dim  intnt As  Intent
    intnt = i
    Log(intnt)
    Log(intnt.ExtrasToString)

    Dim MacObject as Object
    If (intnt.HasExtra("android.bluetooth.device.extra.DEVICE")) Then
         MacObject = intnt.GetExtra("android.bluetooth.device.extra.DEVICE")
         Log ("MacObject: " & MacObject)
    End If
End Sub
 
Last edited:

leongcc

Member
Licensed User
Longtime User
The values are not null.
The Log of the intent show both the keys and the values.
Please see the comment directly below the Log statements.
 
Upvote 0

leongcc

Member
Licensed User
Longtime User
I modified the codes to include the statement,
Log ("MacObject: " & MacObject).
The Log is as follows

B4X:
(Intent)Intent { act=android.bluetooth.device.action.PAIRING_REQUEST fla=0x10 (has extras) }
Bundle[{android.bluetooth.device.extra.DEVICE=00:12:3E:00:16:65, android.bluetooth.device.SECURE=true, android.bluetooth.device.PAIRING_VARIANT=0}]
MacObject: null
 
Upvote 0

leongcc

Member
Licensed User
Longtime User
So HasExtra() is able to recognize the key in the Bundle but GetExtra() is not able to recognize the value that comes after, because the value is not "serializable".
Could you elaborate please?
 
Upvote 0

leongcc

Member
Licensed User
Longtime User
I am not familair with B4A Reflection, could give me an example how Reflection codes look like for Intent.getParcelableExtra()
 
Upvote 0

leongcc

Member
Licensed User
Longtime User
Thanks for you reply.
My app is already working well using B4A BluetoothAdmin and BtSerial but I have to implement a special requirement.

Using the extra value from intent, I want to create a android.bluetooth.BluetoothDevice then access an internal method, setPin(). In Java I would do this:


BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(intent.getParcelableExtra(..))
device.setPin("1234")


I am not sure about B4A Reflection but I think I need it to get this done, and there is a good chance I will mess things up by reflecting BluetoothDevice because BluetoothDevice is a thin wrapper that serves android.bluetooth.BluetoothAdapter that is managed by B4A BluetoothAdmin. Do you think so?

Aternatively, I can write all Bluetooth stuff in Java and put it in a B4A library.

I appreciate some advice.
 
Last edited:
Upvote 0

leongcc

Member
Licensed User
Longtime User
Just to inform that I wrote a Java class and convert it to B4A library.
Now my Android app can programmatically bond(pair) with bluetooth devices.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Bluetooth Library

Hi there, can you share that library you created, i'm sure it will be helpful to a lot of us in here :icon_clap:


Cheers,
Walter
 
Upvote 0
Top