qpython icon indicating copy to clipboard operation
qpython copied to clipboard

Bluetooth couldn't connect to SPP

Open shrlnm opened this issue 7 years ago • 2 comments

Bluetooth fasade couldn't connect to SPP device. I am trying to port my software from old sl4a version to qpython. The part of code is very simple

import androidhelper as android
dr = android.Android()
print dr.toggleBluetoothState(True)
print dr.bluetoothConnect('00001101-0000-1000-8000-00805F9B34FB')

The last line should ask me to choose MAC of BT device but nothing happens and function returns imidiately. The output of this code is as follows.

/data/user/0/org.qpython.qpy/files/bin/qpython-android5.sh "/storage/emulated/0/qpython/scripts/bt.py" && exit
.sh "/storage/emulated/0/qpython/scripts/bt.py" && exit                    <
Result(id=1, result=True, error=None)
Result(id=2, result=None, error=None)

#[QPython] Press enter to exit

The sl4a version r6.1.1 with python 2.7 Bin:29 Extra:29 works fine with this code on the same android device.

Thank you in advance for any help.

shrlnm avatar Sep 09 '17 16:09 shrlnm

Hi, I meet the same problem as you. Did you get the result in the end?

JasonJunjieXu avatar Jul 24 '20 00:07 JasonJunjieXu

Hi The problem is in absence of activity

The file https://github.com/qpython-android/qpysl4a/blob/fc9d47452c2cdd99b1314c2d5f913dfea33698ad/src/main/java/org/qpython/qsl4a/qsl4a/facade/BluetoothFacade.java

have a reference to activity

if (address == null) {
      Intent deviceChooserIntent = new Intent();
      deviceChooserIntent.setComponent(Constants.BLUETOOTH_DEVICE_LIST_COMPONENT_NAME);
      Intent result = mAndroidFacade.startActivityForResult(deviceChooserIntent);
      if (result != null && result.hasExtra(Constants.EXTRA_DEVICE_ADDRESS)) {
        address = result.getStringExtra(Constants.EXTRA_DEVICE_ADDRESS);
      } else {
        return null;
      }
    }

but there is no code of this activity in src

Probably the problem may be solved by getting the list of paired BT devices and connecting directly by MAC address but I didn't find the way how to get the list of connected devices with their names from the script.

shrlnm avatar Dec 26 '22 09:12 shrlnm