私はBeacon検出用のIntentServiceを実装しましたが、BLE Devices検出を開始する際に非体系的な問題が発生しました。ここstartLeScan():IntentServiceのnull
は私のサービスのサンプルコードです:
public class BeaconService extends IntentService{
...
...
@Override
protected void onHandleIntent(Intent intent) {
...do initialization stuffs....
startBLE();
}
public void startBLE(){
mHandler = new Handler();
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Log.d("BeaconService", "Erreur Bluetooth pas de feature Bluetooth sur le mobile...");
}
// Initializes a Bluetooth adapter. For API level 18 and above, get a reference to
mBluetoothAdapter = bluetoothManager.getAdapter();
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
mBluetoothAdapter.enable();
Log.d("JRE","enabling BLE");
}
// Checks if Bluetooth is supported on the device.
if (mBluetoothAdapter == null) {
Log.d("BeaconService", "Erreur d'adapteur Bluetooth...");
return;
}
mHandler.post(scanRunnable);
}
private Runnable scanRunnable = new Runnable()
{
@Override
public void run() {
Log.d("JRE","Round Scan for Beacon started");
if (isScanning)
{
if (mBluetoothAdapter != null)
{
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}
else
{
if (mBluetoothAdapter != null)
{
mBluetoothAdapter.startLeScan(mLeScanCallback);
}
}
isScanning = !isScanning;
mHandler.postDelayed(this, scan_interval_ms);
}
};
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
Log.d("BeaconService","onLeScan callback");
.....do my stuff on detection....
時々、私はエラーを取得するように私は奇妙な行動に直面しています:
startLeScan(): null
06-27 14:25:14.115: I/Timeline(29500): Timeline: Activity_launch_request id:com.jre.ordolink time:43106423
06-27 14:25:14.185: E/ViewRootImpl(29500): sendUserActionEvent() mView == null
06-27 14:25:14.325: D/BluetoothLeScanner(29500): onClientRegistered() - status=0 clientIf=6
06-27 14:25:14.625: D/PhoneWindow(29500): *FMB* installDecor mIsFloating : false
06-27 14:25:14.625: D/PhoneWindow(29500): *FMB* installDecor flags : -2139029248
06-27 14:25:14.965: I/art(29500): Background sticky concurrent mark sweep GC freed 12983(984KB) AllocSpace objects, 7(160KB) LOS objects, 0% free, 40MB/40MB, paused 1.210ms total 314.016ms
06-27 14:25:15.065: W/MessageQueue(29500): Handler (android.os.Handler) {1e3fad36} sending message to a Handler on a dead thread
06-27 14:25:15.065: W/MessageQueue(29500): java.lang.IllegalStateException: Handler (android.os.Handler) {1e3fad36} sending message to a Handler on a dead thread
06-27 14:25:15.065: W/MessageQueue(29500): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:325)
06-27 14:25:15.065: W/MessageQueue(29500): at android.os.Handler.enqueueMessage(Handler.java:631)
06-27 14:25:15.065: W/MessageQueue(29500): at android.os.Handler.sendMessageAtTime(Handler.java:600)
06-27 14:25:15.065: W/MessageQueue(29500): at android.os.Handler.sendMessageDelayed(Handler.java:570)
06-27 14:25:15.065: W/MessageQueue(29500): at android.os.Handler.postDelayed(Handler.java:398)
06-27 14:25:15.065: W/MessageQueue(29500): at com.jre.ordolink.BeaconService$2.run(BeaconService.java:325)
06-27 14:25:15.065: W/MessageQueue(29500): at android.os.Handler.handleCallback(Handler.java:739)
06-27 14:25:15.065: W/MessageQueue(29500): at android.os.Handler.dispatchMessage(Handler.java:95)
06-27 14:25:15.065: W/MessageQueue(29500): at android.os.Looper.loop(Looper.java:145)
06-27 14:25:15.065: W/MessageQueue(29500): at android.os.HandlerThread.run(HandlerThread.java:61)
このエラーが発生する可能性がありますか? – tiamat
これはあなたのスタックトレースが示唆しているものです。 –
私は試しましたが、もう例外はありませんが、まだstartLeScan():null – tiamat