2016-06-27 4 views
0

Bent Devices 탐지를 시작하는 동안 Beacon 탐지를 위해 IntentService를 구현했으며 체계적이지 않은 문제가 발생했습니다.startLeScan() : null on IntentService

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) 

답변

0

는 드디어 다음 사용하여 내 프로젝트 작업을 얻기 위해 다른 방법을 사용 :

private BluetoothLeScanner mBluetoothLeScanner; 
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); 

mBluetoothLeScanner.startScan(mScanCallback); 

//Scan call back function 
private ScanCallback mScanCallback = new ScanCallback() { 
@Override 
public void onScanResult(int callbackType, ScanResult result) { 
    super.onScanResult(callbackType, result); 
    mLeDeviceListAdapter.addDevice(result.getDevice()); 
    mLeDeviceListAdapter.notifyDataSetChanged(); 
} 
}; 

은 누군가가 도움이되기를 바랍니다!

0

내가 스캔 Handler를 사용하지 않는 제안 : 같은 가끔 오류가 발생하는

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.... 

나는 이상한 행동에 직면하고 있습니다 : 여기

내 서비스의 샘플 코드 블루투스 장치 용. 이것은 배경 비동기 작업이며 기본 처리기 스레드는 main입니다. 자신의 스레드를 사용하십시오.

+0

좋아,이 오류가 발생할 수 있으리라고 생각하십니까? – tiamat

+0

그것이 스택 트레이스에서 제안한 것입니다. –

+0

시도했지만 더 이상 예외는 없지만 여전히 startLeScan() : null – tiamat