In my code, I'm trying to unpair a bluetooth device by calling the function.
import android.bluetooth.BluetoothDevice; .....
BluetoothDevice Device = mBluetoothAdapter.getRemoteDevice(address); .......
public vo开发者_JS百科id unpair() { int state = getBondState();
if (state == BluetoothDevice.BOND_BONDING || state == BluetoothDevice.BOND_BONDED) {
Device.cancelBondProcess(); //Error in this line
}
Seems like you are using a non-public API cancelBondProcess(), In addition this APIs sounds like it will only cancel the process that is ongoing , i.e when the state is BOND_BONDING, if the device is already bonded it will fail / return error. You will need to removeBond() to remove the bonded device - again this is also non-public API and not recommended if you plan on keeping your application compatible with various versions of android releases.
There are no public APIs currently to accomplish canceling or removing of bond.
精彩评论