我试图在Android Studio中使用我的galaxy平板电脑扫描所有可用的蓝牙(LE)设备,但设备没有显示。我只能在没有调试的情况下运行此应用程序时看到所有设备。
ScanActivity:当我运行代码时,设备显示在回收器视图中,但在我尝试调试时则不显示。
public class ScanActivity extends RxAppCompatActivity {
...
private ScanResultsAdapter resultsAdapter;
private IBluetoothService bluetoothService;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
ButterKnife.bind(this);
configureResultList();
handleScanResult();
}
@Override
protected void onStart() {
super.onStart();
Intent intentBluetooth = new Intent(this, BluetoothLEService.class);
bindService(intentBluetooth, connectionBluetooth, Context.BIND_AUTO_CREATE);
doShortScan();
}
public void handleScanResult() {
Handler handler = new Handler();
handler.post(new Runnable() {
@Override
public void run() {
if (boundBluetooth) {
if (bluetoothService.hasScanResult())
resultsAdapter.addScanResult(bluetoothService.getScanResult());
}
handler.postDelayed(this, 100);
}
});
}
尝试运行该应用程序然后转到android studio工具栏:
Run -> Attach To Process
还要确保已将连接的设备作为MTP选项。
如果仍然无法解决问题,请尝试重新启动Android Studio和您的设备。