2016-08-07 7 views
0

Android Developersサイトのドキュメントに従ってBluetooth LE機能を持つ基本的なAndroid Appを設定しようとしています。私はスキャンを開始しているところに到達することができますが、テストするために使用しているペリフェラルは見つけられません。コードはそのままです:Android Bluetooth Low Energy Not Finding Devices

public class MainActivity extends AppCompatActivity implements View.OnClickListener { 

@Bind(R.id.button) Button mButton; 
@Bind(R.id.listView) ListView mListView; 

private BluetoothAdapter mBluetoothAdapter; 
private boolean mScanning = true; 
private Handler mHandler; 
private static final long SCAN_PERIOD = 10000; 
BluetoothLeScanner mBluetoothAdapterBluetoothLeScanner; 
ArrayList<String> bluetoothArray = new ArrayList<>(); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    ButterKnife.bind(this); 
    mButton.setOnClickListener(this); 
    Context mContext = getBaseContext(); 
    final BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE); 
    mBluetoothAdapter = bluetoothManager.getAdapter(); 
    mBluetoothAdapterBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); 

    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) { 
     Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
     startActivityForResult(enableBtIntent, 1900); 
    } 
} 

@Override 
public void onClick(View view) { 
    scanLeDevice(mScanning); 
} 

private void scanLeDevice(final boolean enable) { 

    if (enable) { 
     // Stops scanning after a pre-defined scan period. 
//   mHandler.postDelayed(new Runnable() { 
//    @Override 
//    public void run() { 
//     mScanning = false; 
//     mBluetoothAdapter.stopLeScan(mLeScanCallback); 
//    } 
//   }, SCAN_PERIOD); 

     mScanning = true; 
     mBluetoothAdapter.startLeScan(mLeScanCallback); 

    } else { 
     mScanning = false; 
     mBluetoothAdapter.stopLeScan(mLeScanCallback); 
    } 
} 

private BluetoothAdapter.LeScanCallback mLeScanCallback = 
     new BluetoothAdapter.LeScanCallback() { 
      @Override 
      public void onLeScan(final BluetoothDevice device, int rssi, 
           byte[] scanRecord) { 
       runOnUiThread(new Runnable() { 
        @Override 
        public void run() { 
         Log.d("test" ,device.getName()); 

        } 
       }); 
      } 
     }; 
} 

答えて

0

広告データの内容は正確に分かりますか?おそらく、Bluetoothスタック(bluetooth.default.so)によってブロックされている可能性があります。たとえば、広告デバイスがADフラグの「検出可能ビット」を設定していない場合、ブロックされ、コールバック関数でレポートを受信しません。

関連する問題