Android Question BLE and HM-1x modules, why does the BLE2 library works, then it doesn't?

ema01

Member
Licensed User
Longtime User
Hello all,
I am new to android programming and B4A, i tried to run the example project here
https://www.b4x.com/android/forum/threads/ble-hm-10-module-broadcasting-a-single-byte.65785/#content

(because i'm developing an app that will connect to an HM-11 module -The UUID is the same-) and it didn't work, a message said that the app was corrupted when trying to install.
After many searches and looking at other Apps where BLE was working (including an old one from a coworker) i found out that i had to change the manifest file in order for the BLE2 Library to work.

I first changed the recommended sdk from "14" to "19" (the one he used), then i could install the app. However, it never hit the DeviceFound Sub.

I found out that as i'm using B4A V8.00 (coworker used 5.2) i had to remove this line from the manifest
B4X:
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light")
and then the app was able to find devices.

I wanted then to suppress the minimum recommended sdk warning and changed it to "26", but now the app can't find devices anymore. Crazy..
I don't really know what to do other than Leave things as they are because it is working, but it's not my style. i'd like to understand what's happening and why..

Other data:
B4A B8.00
BLE2 Library Version 1.36, the one i found here https://www.b4x.com/android/forum/threads/ble-2-bluetooth-low-energy.59937/#content
Reference on the manifest thing here https://www.b4x.com/android/forum/threads/version-safe-themes.87694/#content

Device i'm trying the app on: Samsung J-510FN with Android 7.1.1

Thanks :)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light")
This line should be removed though it will not affect BLE behavior.

Looks like there is a new requirement.

1. Add this to the manifest editor:
B4X:
AddPermission(android.permission.ACCESS_COARSE_LOCATION)

2. You need to request this permission at runtime in Activity_Create and only then start scanning.
See the runtime permissions tutorial (watch the video): https://www.b4x.com/android/forum/threads/67689/#content
 
Upvote 0

ema01

Member
Licensed User
Longtime User
Hi erel,
sorry for my late reply.

Thank you :)
I think there were many things wrong that now i finally understand.
When i added the RuntimePermission library i would get FontFamilyFont related errors during compile.
searching pointed me to this thread
https://www.b4x.com/android/forum/threads/runtimepermissions-library-issue.89210/

turns out i too was updating the sdk but was still using an old one (sdk version 25 in my case, this may also explain why i would get "corrupted app" if i set the recommended sdk version to "26")
i changed the sdk path and now it compiles and i can discover and connect to BLE devices :)
 
Upvote 0
Top