Currently Iam using backport.android.bluetooth2.jar file for bluetooth programming with Android 1.5.Whenever device pairing fails it populates alert dialog for passKey and if i give passkey then in my log iam getting below error
07-21 12:25:52.419: WARN/BluetoothDeviceService(948): setPin(00:0E:6D:BA:89:F3) called but no native data available, ignoring. Maybe the PasskeyAgent Request was cancelled by the remote device or by bluez.
For successfully pair my BT device I always rebooting my tablet and manually pair the device with Settings options.So at last i realised to give this passKey programmatically but i haven't found any method for this.But in google opensource i found one method that is commented with #hide setPassKey(String Address,int passKey) in BluetoothDevice.java of backport.android.bluetooth2.jar .This will n't appear in my jar file.If any way is there for pairing the unbounded device please give reply ASAP?
In the AndroidBluetoothAPI_0.3.jar file following methods are available i,e: pair(address) and setPin() for setting the pin programmatically and connecting the BT device.For finding the signal strength method is available in this api.Below is the code project link
http://code.google.com/p/android-bluetooth/downloads/detail?name=AndroidBluetoothAPI_0.3.jar&can=2&q=
Related
Background
A long time ago I was tasked with making a android app for the Wii Balance Board, after some screwing around I found that android no longer supported L2CAP. More research lead to understand that it was being re-added in Android 10. With Android 10 out I've been trying to give it a crack now.
Problem
So my simple goal at the moment is to create a connection with the Wii Balance Board.
My approach for connection is:
Start discovery
Add discovered bluetooth devices to list
When you click on a device it then tries to open a socket as such:
bluetoothSocket = btDevice.createInsecureL2capChannel(port);
As mentioned on the WiiBrew site I'm using psm value 0x13 for input and 0x11 for output.
I then use bluetoothSocket.connect and proceed to receive a IOException (timeout error)
I've also tried using both createL2capChannel and createInsecureL2capChannel with same results
I was able to successfully pair to the device using btDevice.createBond() and then using the phones BT address backwards for .setpin() and the Wii Balance Board simply acts as a "dumb" input device. (not sure if pairing is needed/good idea)
The above is a simplified flow of how I'm trying to connect. I've also tried using BalanceBoard.java from Paul Burton's fitscales repo updating all of the old bluetooth code, again I still get the timeout.
Have you looked at the bt_stack logs?
Here is mine from trying to open a socket with a wiimote:
04-05 12:25:04.949 E/bt_stack(4895): [ERROR:btif_sock_l2cap.cc(244)] SOCK_LIST: free(id = 4) - NO app_fd!
04-05 12:25:04.949 I/bt_stack(4895): [INFO:btsnoop.cc(323)] clear_l2cap_whitelist: Clearing whitelist from l2cap channel. conn_handle=65535 cid=65:0
04-05 12:25:04.949 E/bt_l2cap(4895): L2CA_FreeLePSM: Invalid PSM=19 value!
04-05 12:25:40.141 I/bt_stack(4895): [INFO:btsnoop.cc(323)] clear_l2cap_whitelist: Clearing whitelist from l2cap channel. conn_handle=1 cid=66:64
04-05 12:25:55.736 I/bt_stack(4895): [INFO:btsnoop.cc(323)] clear_l2cap_whitelist: Clearing whitelist from l2cap channel. conn_handle=2 cid=67:65
I believe this is where the problem lies, Im only a novice so Im not sure what can be done about it. I know the old ways of connecting passed the fd as a parameter to the bluetooth socket constructor but I dont think this is possible anymore
I am tring to setup WIFI P2P on 2 devices using
manager.addLocalService(channel, service, ActionListener)
and then connect both devices using
manager.connect(channel, config, ActionListener).
I would like to know which method is called before the popup to accept/reject connection is shown on the target device. All I was able to find was onConnectionInfoAvailable(WifiP2pInfo p2pInfo), but it is called after the connection is established.
I basically want to receive the "instance name" of the device trying to connect to me using WIFI P2P and then reject the connection request without showing system dialog(that allows the user to accept/reject connection).
I can't anything that can help me do this on docs or any other place. If anyone knows how to do it or can point me in the right direction then please let me know.
I solved it. I can put the instancename and devicename (of device I want to connect to) in Map that is passed when setting up service. From other device I can retrieve map of all devices available using this and find the instancename of one I need.
I'm trying to connect my app to the RN42 module.
// Create a socket based on the application ID with a paired device
// Fetch the published UUIDs from the mbed and use the first one
bluetoothSocket = connectedDevice.createRfcommSocketToServiceRecord(connectedDevice.getUuids()[0].getUuid());
// Connect to the device
if (!bluetoothSocket.isConnected())
bluetoothSocket.connect();
// Create the input and output streams for sending/receiving messages
socketInput = bluetoothSocket.getInputStream();
socketOutput = bluetoothSocket.getOutputStream();
I've got these in the Android Manifest
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
I'm getting this error when I call bluetoothSocket.connect().
Attempt to invoke virtual method 'void android.bluetooth.BluetoothSocket.connect()' on a null object reference
After calling this line
bluetoothSocket = connectedDevice.createRfcommSocketToServiceRecord(connectedDevice.getUuids()[0].getUuid());
I've inspected the variable bluetoothSocket using Android Studio and it's not null. It somehow becomes null when bluetoothSocket.connect() is called.
Is that the expected behaviour? What can I do to fix it? The RN42 module works fine as I've tested it with the RN Bluetooth Chat app on Play Store.
I'm on Android 5.1 on a Nexus 7 if that helps.
I've managed to sort the issue by removing my Bluetooth connectivity code and instead basing it around the Android Bluetooth Chat example. I don't know what the exact issue was but Bluetooth Chat example managed to fix it. Nothing obvious stands out so my best guess is, it was something subtle. If you are having a similar issue and connection between RN42 and Android is fiddly, create a sample Bluetooth Chat application and reuse that Bluetooth connectivity code.
Many less headaches! :)
Seethis reference guide for the module (p. 21) .
This might or might not apply to your case but is probably worth trying. They have special recommendations (default UUID and custom UUID respectively) for the module when connecting to Android devices.
Use the createInsecureRfcommSocketToServiceRecord instead. Insecure socket allows the RFCOMM to communicate with a non-authenticated paired device. Embedded devices like the RN42 or KC2114 have a difficult time performing authenticated pairing, because user interaction is required (numeric comparison, yes-no response). The "Just Works" automatic pairing will not produce an authenticated pairing. KC2114 supports both automatic authenticated pairing (with a small hack) and Just Works non-authenticated pairing.
Source:
The OPs Working Solution:
Sending a File using Bluetooth OBEX Object Push Profile (OPP)
I am trying to use this source in order to test transfer with my app. I have also tried running with variants but the main issue I am getting is that Eclipse wants to initialize this line:
BluetoothDevice device;
to
BluetoothDevice device=null;
In which case then the app gives me an error upon running.
In another case with similar code it will flag a problem with the actual getAddress().
Am I missing something here? Is it because I need to setup a bluetooth connection previously?
Usually BluetoothDevice is available when you find a remote device,
Hence you should first use BluetoothAdapter to discover remotedevices then use the code to send data to the remotedevice.
you can find a great tutorial in this regard here: (http://www.developer.android.com/guide/topics/connectivity/bluetooth.html‎)
Can anyone give me an idea on how to read the values from the OBD II Bluetooth adapter in an android application.
I want to start with scanning for the bluetooth devices from my android application, then after bluetooth device is found, how would I interact with it and get the values from it?
You should start by reading this http://developer.android.com/guide/topics/wireless/bluetooth.html
it contains step by step procedure .
add required permissions,
make a bt adapter,
then find paired/unpaired devices
I used the BluetoothChat Application and was able to get some basic communications, I am not moving into data logging. You can use this application to have a sort of instant messenger conversation with your ECM.
What particular dongle are you using?
Do you know what protocols are in use within your vehicle?
Download the BluetoothChat sample application -
They will have already handled the intricacies of the connection for you, you will have to change the UUID in order to connect with your device - 00001101-0000-1000-8000-00805F9B34FB
Read up on your particular dongle, some require the return character to be sentat the end of every command "\r"
This should get you started!
Once you have made the Bluetooth connection using the android bluetooth api, use the transport to send and receive data via the Bluetooth channel.
This is new developer resource document:
https://developer.android.com/guide/topics/connectivity/bluetooth.html
The general workflow of the application functionality should go like this:
1) connect to the OBDII adapter through Bluetooth;
2) initialize OBDII adapter with AT commands;
3) continuously get data from the vehicle through issuing the corresponding PID codes.
This article also may be helpful.
http://blog.lemberg.co.uk/how-guide-obdii-reader-app-development