NaitLee / Cat-Printer

Application supporting Bluetooth thermal “Cat Printers”, for everyone!
GNU General Public License v3.0
334 stars 33 forks source link

Android app: can't scan devices on Android 12 (or above) #41

Closed pferreir closed 1 year ago

pferreir commented 1 year ago

Every time I try to scan a device I get an error:

Error: API Failure  
at handleBluetoothProblem (http://127.0.0.1:8095/~every.js:1475:17)  
at async http://127.0.0.1:8095/~every.js:739:45  
at async callApi (http://127.0.0.1:8095/~every.js:729:12)  
at async Main.searchDevices (http://127.0.0.1:8095/~every.js:1482:29)  
{  
"name": "Exception",  
"details": "JVM exception occurred: Need android.permission.BLUETOOTH_SCAN permission for android.content.AttributionSource@3d8431d6: GattService registerScanner java.lang.SecurityException"  
}

If I try again:

Error: API Failure  
at handleBluetoothProblem (http://127.0.0.1:8095/~every.js:1475:17)  
at async http://127.0.0.1:8095/~every.js:739:45  
at async callApi (http://127.0.0.1:8095/~every.js:729:12)  
at async Main.searchDevices (http://127.0.0.1:8095/~every.js:1482:29)  
{  
"name": "BleakError",  
"details": "A BleakScanner is already scanning on this adapter."  
}

The app has permissions "Location" and "Nearby Devices" set to "Allowed". I am on Android 13.

NaitLee commented 1 year ago

Sadly I can’t gather an Android 13 phone to give a test.

BLUETOOTH_SCAN is defined in build parameters, and with built app my phone (Android 11) have no problem.

Double check if the basic Bluetooth permission was given. Maybe also to check if it’s shown in permission details when installing. Which version are you using: 0.6.1 or 0.6.0.2? There are technical differences between them, so try the other version if one isn’t right.

parkerlreed commented 1 year ago

I'm on Android 12 on a Samsung Note 10 and seeing the same thing. Location and nearby devices is enabled in permissions but the first scan says it doesn't have permissions and then when you try to do it again it says there's already a scanning thread going on.

This is on 0.6.1

parkerlreed commented 1 year ago

Same on 0.6.0.2

Screenshot_20220918-185542_Cat Printer Screenshot_20220918-185552_Permission controller

parkerlreed commented 1 year ago

Here's a thread on some possible extra permissions that might be needed https://stackoverflow.com/questions/67722950/android-12-new-bluetooth-permissions

NaitLee commented 1 year ago

Sorry for being late. I just got time to test on an Android 12 device and reproduced it.

Obviously there should be extra code for requesting permission on Android 12+, as said in your link.

The code in theory could be in server.py, using python-for-android android or pyjnius package.

But the painful part is, I really have no idea to know where those Java namespaces/classes are coming from. (I’m wondering if asking in Stack Overflow will help)

The code could also be in the Java files (mentioned in the Android build env instruction), but I’m tired about them :(

(It’s a bit holiday for me, without guarantee to do anything, for life matters being messy)

NaitLee commented 1 year ago

Didn’t notice this closed automatically. Try the new release 0.6.2.0 and see if it’s solved?

sync1211 commented 1 year ago

0.6.2.0 does not seem to work for me on Android 12. I'm going to try and rebuild it using the latest commit to see if it might be a dependency issue.

sync1211 commented 1 year ago

The app still works when I compile it using the latest commit.

I am using p4a Version 2023.01.28, which does not support --orientation user (I've used --orientation portait for builds). I'm using NDK version r25b with an API target of 30 (Build says "min API 21").

The only real with my build process is that I've downloaded bleak from PyPi, instead of from GitHub. (missing Setup.py)

I am building the app on Manjaro 22.0.2 without the docker environment.

NaitLee commented 1 year ago

I’ve upgraded p4a (2023.02.10) and ndk (r25b) to build this one: cat-printer-android-0.6.2.1.apk.zip (I don’t know if bleak is updated) it’s a release build, you may remove the zip suffix and install as apk. If it’s ok then let’s release it. (hardly see android 12+ around me)

pferreir commented 1 year ago

Hi there, thanks for the update! I've just tested it and unfortunately it doesn't seem to work yet. I get the same thing about needing "Bluetooth" permission.

On Sun, 12 Feb 2023, 16:30 NaitLee, @.***> wrote:

I’ve upgraded p4a (2023.02.10) and ndk (r25b) to build this one: cat-printer-android-0.6.2.1.apk.zip https://github.com/NaitLee/Cat-Printer/files/10716382/cat-printer-android-0.6.2.1.apk.zip (I don’t know if bleak is updated) it’s a release build, you may remove the zip suffix and install as apk. If it’s ok then let’s release it. (hardly see android 12+ around me)

— Reply to this email directly, view it on GitHub https://github.com/NaitLee/Cat-Printer/issues/41#issuecomment-1427060991, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAAVC2RAI6BAUP5GGJHSULWXD6YBANCNFSM6AAAAAAQPMCJFI . You are receiving this because you authored the thread.Message ID: @.***>

NaitLee commented 1 year ago

I cleaned up by build environment but can’t put it back anymore. Until some day I’m lucky enough…

@sync1211 you may put your build here if you want :)

sync1211 commented 1 year ago

I haven't been able to sign my builds yet, so I only have a debug build atm: cat-printer-debug-0.6.2.0.zip

Cratesmith commented 1 year ago

Can confirm that the release doesn't work on my phone/mx06 but @sync1211's debug build did.

sync1211 commented 1 year ago

I've managed to replicate the build using an archlinux docker environment.

The steps are almost the same as the manual-build guide. You can find my notes for building within docker in this Gist.

NaitLee commented 1 year ago

FINALLY I got the environment to work. Here’s a debug build with almost all of the newest things: cat-printer-debug-0.6.2.1.apk.zip. (remove the .zip suffix and install it)

Please give it a test!

sync1211 commented 1 year ago

I just installed it and managed to scan and print successfully.

NaitLee commented 1 year ago

Thanks to all of you, there’s 0.6.2.1 😄

NaitLee commented 1 year ago

No problems so far, closing this gracefully 🎉