作者huadi73 (ㄚㄚㄚ)
看板AndroidDev
标题[问题] 蓝芽LE不断接收
时间Fri Apr 4 13:02:35 2014
我想不断的接收蓝芽讯息, 即使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://webptt.com/cn.aspx?n=bbs/AndroidDev/M.1396587760.A.51E.html