Question

I'm trying to develop an App to receive continuous data from an Bluetooth device which is not an Android.So my question is that Is it possible by android java to do this by programming or do I need to have any SPP supporting software to be installed in Android phone?

Any idea or help regarding this will be appreciated. Thanks in advance.

Était-ce utile?

La solution

Short answer: Yes you can
Android provides BluetoothSocket that :

It is also known as the Serial Port Profile (SPP)

This class offers you two streams (one for reading and one for writing) that you can use to read/write bytes.
Example of opening a socket:

BluetoothDevice mBtDevice;
BluetoothSocket mBtSocket;
mBtSocket = mBtDevice.createRfcommSocketToServiceRecord(MY_UUID);
mBtSocket.connect();

Of course in order to do that the other device must be paired with your phone. After they are paired you can select your device from the list of paired devices provided to you by:

BluetoothAdapter    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top