Implementing own bluetooth profile for android
I'm trying to implement Handsfree bluetooth profile for android (HF side). I have succesfully connected through rfcomm and i开发者_StackOverflowt allows me to send/receive AT commands to/from AG. But what about voice? In documentation I have read about synchronous connection, and tried to accept connection from SCO socket:
int sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO)
But nothing happens.
Is this a correct type of socket, or I need something different then SCO?
You may take inspiration from the class ScoSocket.java
located in frameworks/base/core/java/android/bluetooth
. You will see that it calls native functions rather than socket(AF_BLUETOOTH...)
. As it used by the Phone app, you may rely on it.
/** Connect this SCO socket to the given BT address.
* Does not block.
*/
public synchronized boolean connect(String address, String name) {
if (DBG) log("connect() " + this);
if (mState != STATE_READY) {
if (DBG) log("connect(): Bad state");
return false;
}
acquireWakeLock();
if (connectNative(address, name)) {
mState = STATE_CONNECTING;
return true;
} else {
mState = STATE_CLOSED;
releaseWakeLockNow();
return false;
}
}
private native boolean connectNative(String address, String name);
精彩评论