我想不斷的接收藍芽訊息, 即使APP已關閉
所使用了官方範例, 並將 bindservice改為 startservice
而在Service中的onCreate做了initialize()以及connect()
當我要開始接收藍芽的資料時
我發現我 connectGatt 的 callback 都沒有呼叫到
BluetoothGattService 也都是 null
我把讀取寫成這樣也還是 NULL
public String read()
{
BluetoothGattService gattService =
mBluetoothGatt.getService(UUID.fromString("00002220-0000-1000-8000-00805f9b34fb"));
if (mBluetoothGatt == null)
{
Log.w(TAG, "mBluetoothGatt not initialized");
return "mBluetoothGatt not initialized";
}
else if(gattService == null)
{
Log.w(TAG, "gattService not initialized");
return "gattService not initialized";
}
BluetoothGattCharacteristic characteristic =
gattService.getCharacteristic(RFduinoUUIDs.Receive_Characteristic_UUID);
return "" + mBluetoothGatt.readCharacteristic(characteristic);
}
附上我 Service 的程式碼 http://pastebin.com/PY87wJ12
想請問我哪裡出錯呢?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.135.47.73
※ 文章網址: http://www.ptt.cc/bbs/AndroidDev/M.1396587760.A.51E.html