馬上加入Android 台灣中文網,立即免費下載應用遊戲。
您需要 登錄 才可以下載或查看,沒有帳號?註冊
x
我要開發一個Android 4.3的防丟器功能,目前功能可以搜尋、連線
1. 使用設定中的藍芽連接過的裝置可以利用getBondedDevices列出,但無法記憶透過我APP連線過的裝置,列出配對過的裝置程式如下,getBondedDevices是屬於API 18?? 可以用於藍芽4.0裝置的嗎?
Set<BluetoothDevice> setPairDevice = mBluetoothAdapter.getBondedDevices();
if(setPairDevice.size() > 0) {
for(final BluetoothDevice device : setPairDevice) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
mLeDeviceListAdapter.addDevice(device);
mLeDeviceListAdapter.notifyDataSetChanged();
}
});
}
}
2.目前想要擷取連接後的藍芽裝置的訊號強度,將readRemoteRssi在GattCallback中呼叫,但使用readRemoteRssi與OnreadRemoteRssi時,在Log上看,回傳的值都是0。程式如下:
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status,
int newState) {
// TODO Auto-generated method stub
String intentAction;
if(newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
mBluetoothGatt.readRemoteRssi();
.
.
.
.
.
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
}
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
final Intent rssiIntent = new Intent(BluetoothLeService.this, DeviceControl.class);
rssiIntent.putExtra(DeviceControl.RSSI, rssi);
}
};//BluetoothGattCallback End
找尋很多資料 可是都不太適用,希望有人知道的可以教教我
或是readRemoteRssi的正確用法???
謝謝大家!!!! |