akexorcist / BluetoothSPPLibrary

[UNMAINTAINED][Android] Bluetooth Serial Port Profile which comfortable to developer application to communication with microcontroller via bluetooth
Apache License 2.0
1.7k stars 570 forks source link

Not scanning or discoverying nearby bluetooth devices. (startActivityForResult) #107

Open ritchie-tg opened 4 years ago

ritchie-tg commented 4 years ago

Greetings, Firstly, thanks for this awesome library. I used it about a year ago for an ESP32 project I was doing. Everything was working great. I revisited that same - once working - project to find issues. A problem I've been having is the only devices detected on the activity (BluetoothState.REQUEST_CONNECT_DEVICE) are devices I have paired through Android's settings. When I press scan for devices, it doesn't scan. The client device is available and detected when using Android setting for Bluetooth > pair a new device. But not in the app, using this library. This happens on three Android devices I own from a Google Nexus 5, Moto x4, and Moto G7 Power.

I'm not sure what is the difference between then and now?

I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 2
I/Choreographer: Skipped 62 frames!  The application may be doing too much work on its main thread.
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@6dda9fa
D/BluetoothSPP: doDiscovery()

And nothing further.

bt.startService(BluetoothState.DEVICE_OTHER); // start bluetooth service
bt.setupService(); // setup bluetooth service
Intent intent = new Intent(getApplicationContext(), DeviceList.class);
startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

I manually request permission for each permission. Only write access is promoted and requested because Bluetooth isn't considered "dangerous." Yet, when pressing the connect button, I am not asked for bluetooth permissions at all.

The readme state to declare <activity android:name="app.akexorcist.bluetoothspp.DeviceList" /> which I'm guessing you meant in the AndroidManifest.xml? The name is red and flagged in Android studio. No idea. I can't seem to find an answer on that.

felangga commented 3 years ago

having this same issue,

I just found out that it's only showing the paired devices.

image

ghost commented 3 years ago

I've moved onto the flutter blue libraries. They're currently updated.