Android 台灣中文網

標題: 關於Android 4.3 藍芽4.0程式開發的幾個相關問題請教 [打印本頁]

作者: x22819    時間: 2013-10-20 18:23
標題: 關於Android 4.3 藍芽4.0程式開發的幾個相關問題請教
我要開發一個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的正確用法???


謝謝大家!!!!
作者: Wen-Chin-Huang    時間: 2013-10-21 16:21
該不會是tiny finder~~XDD
作者: x22819    時間: 2013-10-22 18:56
Wen-Chin-Huang 發表於 2013-10-21 16:21
該不會是tiny finder~~XDD

應該類似吧@@
只是功能應該比較簡單
作者: Wen-Chin-Huang    時間: 2013-10-30 16:46
getBondedDevices 是 18的

參考一下兩篇因為我看不太懂你的問題~~XDD

http://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#readRemoteRssi()

http://developer.android.com/reference/android/bluetooth/BluetoothGattCallback.html#onReadRemoteRssi(android.bluetooth.BluetoothGatt,%20int,%20int)




歡迎光臨 Android 台灣中文網 (https://apk.tw/) Powered by Discuz! X3.1