Android Question BLE automatic scanning and connection ( on the example of a project: BLEExample.zip)

Picon

Member
Licensed User
Hello

I learn from the example https://www.b4x.com/android/forum/threads/b4x-ble-2-bluetooth-low-energy.59937/#content of by Erel.
The task I set myself was to skip using the "btnScan" button, so that the application automatically searched for a specific device and automatically connected to it.
Seems simple, but ....

If I put the function call "btnScan_Click" somewhere in another function, the program lines following the expression:
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
are no longer performed and the program does not start scanning ("StartScan" function)

The program, after line "Wait For...." jumps to the function "Activity_PermissionResult" (in Main module code), then calls the function B4XPage_Appear (in the moduleB4XMainPage) and ends there.

I don't understand why this is happening.

An extra line in the manifest is added:
AddPermission (android.permission.ACCESS_FINE_LOCATION)

Appropriate permissions are set on the smartphone.

B4X:
Sub btnScan_Click
    #if B4A
    'Don't forget to add permission to manifest
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)

'==================  break in the run. ===== The next lines are skipped.=======
    If Result = False Then
        ToastMessageShow("No permission", True)
        Return
    End If
    #end if
    pbScan.Show
    StartScan              'this line dont work
End Sub
 

Picon

Member
Licensed User
This means that you have an old copy of RuntimePermissions.jar in the internal libraries folder. Delete it and reinstall B4A.
My version is 1.12.
I noticed that this function containing "Wait For B4XPage_PermissionResult" must be in B4XMainPage.
Then it works fine.
When it is moved to another party's program code, then the return mechanism from Main (exactly from Activity_PermissionResult) has some problems finding the right place for this function.

I left my function in B4XMainPage and it works fine (subsequent commands are executed)

Thanks to Erel for the answer.
greetings
 
Upvote 0
Top