First off, I AM able to programmatically connect to a device via bluetooth if I have manually paired it beforehand. However, I haven't found a (user-friendly) way to connect with unpaired devices (that are discoverable, obviously), even using the unchanged sample Android Bluetooth code.
I would like to pop up the pairing dialog box that requests the user to input a passkey for the device. What happens with my code, and the sample Android Bluetooth code, is that making a socket with a discoverable bluetooth device
device.createRfcommSocketToServiceRecord(MY_UUID);
will add a notification to the notification bar at the top of开发者_C百科 the screen; however, it is pretty unlikely that the user will even notice a new notification (I know I didn't).
How would I pop up that pairing dialog box, prompting the user to enter the passkey - or better yet, supply a passkey for a particularly device automatically?
You can use BlueCove library to do that. However, it may be a bit heavier than you'd want as it requires a native component but in return gives you real access to Bluetooth on your phone.
Tim: I can see how a rogue app could abuse this mechanism but there are devices out there which don't support traditional PIN-based authentication method at all (for example the WiiMote).
I've seen a few threads on this but haven't really found a good answer.
I am connecting my nexus 1 to a bluetooth spp server device to read and write data.
After some experimentation I have found the following
If I offload the establishment of the connection from the UI thread (which I would consider a good idea) the pairing dialog (enter pin) is not displayed - rather a notification item appears which the user must click to pair the devices.
If I establish the connection from within the UI thread then the paring dialog will come to the foreground but obviously there is a small ugly UI pause while waiting for this.
In either case the request to establish the connection is timing out before the user (me) can enter the pin with an IOException Service discovery failed.
My ideal would be that the pairing dialog comes to the front (without have to block my UI thread) and that the connection attempt would not time out while waiting on pairing entry.
Has anyone else come up with a way to make this work?
精彩评论