Bluetooth LE (RxAppCompatActivity) - Debugging

问题: I am trying to scan all available bluetooth (LE) devices with my galaxy tablet in Android Studio but the devices don't show up. I can only see all the devices when I run th...

问题:

I am trying to scan all available bluetooth (LE) devices with my galaxy tablet in Android Studio but the devices don't show up. I can only see all the devices when I run this application without debugging.

ScanActivity: devices are shown in recycler view when I run the code but not when I try to debug.

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);
        }
    });
}

回答1:

Try running the app and then go to android studio toolbar:

Run -> Attach To Process

also make sure you have connected device as MTP option.

If still you are unable to resolve the issue try restarting Android studio and your device as well.

  • 发表于 2019-03-10 23:59
  • 阅读 ( 86 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除