M Mike1970 Well-Known Member Licensed User Longtime User Jun 5, 2022 #1 Hi everyone, I'm moving part of my code done in a B4XPage into a Standard Class. In this code i've a Runtime Permission CheckAndRequest that requires the "Wait For" block B4X: Private Sub BeginBLEscan rp_ble.CheckAndRequest(rp_ble.PERMISSION_ACCESS_FINE_LOCATION) Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean) If Result = False Then ToastMessageShow("Permesso Bluetooth non fornito", True) Return End If End Sub Well... in this manner this does not work, the "Wait For" will never fire because it calls the "B4XPage_PermissionResult" in the module where I declared the class. Example: 1. I initialized the "ClassA" in the B4XPage called "Home" 2. In the "ClassA" there is the Runtime Permission WaitFor 3. When it should be fired, insted, this appears in the Logs -> *** home: B4XPage_PermissionResult [home] It is delegated to the B4XPage instead of the Class... How can i solve this issue (beside of moving the check outside the class)? Thanks in advance
Hi everyone, I'm moving part of my code done in a B4XPage into a Standard Class. In this code i've a Runtime Permission CheckAndRequest that requires the "Wait For" block B4X: Private Sub BeginBLEscan rp_ble.CheckAndRequest(rp_ble.PERMISSION_ACCESS_FINE_LOCATION) Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean) If Result = False Then ToastMessageShow("Permesso Bluetooth non fornito", True) Return End If End Sub Well... in this manner this does not work, the "Wait For" will never fire because it calls the "B4XPage_PermissionResult" in the module where I declared the class. Example: 1. I initialized the "ClassA" in the B4XPage called "Home" 2. In the "ClassA" there is the Runtime Permission WaitFor 3. When it should be fired, insted, this appears in the Logs -> *** home: B4XPage_PermissionResult [home] It is delegated to the B4XPage instead of the Class... How can i solve this issue (beside of moving the check outside the class)? Thanks in advance
H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Jun 5, 2022 #2 Move your sub BeginBLEscan back to your (any) VISIBLE module, then call it from your INVISIBLE standard class such as: B4X: CallSubDelayed(Main,"BeginBLEscan") Upvote 0
Move your sub BeginBLEscan back to your (any) VISIBLE module, then call it from your INVISIBLE standard class such as: B4X: CallSubDelayed(Main,"BeginBLEscan")
M Mike1970 Well-Known Member Licensed User Longtime User Jun 5, 2022 #3 Hamied Abou Hulaikah said: Move your sub BeginBLEscan back to your (any) VISIBLE module, then call it from your INVISIBLE standard class such as: B4X: CallSubDelayed(Main,"BeginBLEscan") Click to expand... Uhm actually i was trying to create a class that is self-contained.. so it can be used in different project without have to create specific functions outside... sparse in the code. If what I want to do is impossibile.. i will do like you say. Thanks Upvote 0
Hamied Abou Hulaikah said: Move your sub BeginBLEscan back to your (any) VISIBLE module, then call it from your INVISIBLE standard class such as: B4X: CallSubDelayed(Main,"BeginBLEscan") Click to expand... Uhm actually i was trying to create a class that is self-contained.. so it can be used in different project without have to create specific functions outside... sparse in the code. If what I want to do is impossibile.. i will do like you say. Thanks
H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Jun 5, 2022 #4 Mike1970 said: is impossibile Click to expand... According my knoweldge, runtimepermission is end user conscent, that is mean it should be visible to him, this can't be achieved by invisible module. Upvote 0
Mike1970 said: is impossibile Click to expand... According my knoweldge, runtimepermission is end user conscent, that is mean it should be visible to him, this can't be achieved by invisible module.
Andrew (Digitwell) Well-Known Member Licensed User Longtime User Jun 5, 2022 #5 There is no simple way to do this. However, one way is to provide an event which the parent calls, such as ClassPermissionResult. So in the parent you need priva B4X: private sub B4xpage_permissionresult(Permission As String, Result As Boolean) if (xui.subexists(mysubclass,"Class_PermissionResult",2) then ' Call child Callsubdelayed3(mysubclass,"Class_PermissionResult",Permissions,result) end if end sub in the class you no have B4X: Private Sub BeginBLEscan rp_ble.CheckAndRequest(rp_ble.PERMISSION_ACCESS_FINE_LOCATION) Wait For Class_permissionResult (Permission As String, Result As Boolean) ' Wait for call from parent If Result = False Then ToastMessageShow("Permesso Bluetooth non fornito", True) Return End If End Sub Upvote 2
There is no simple way to do this. However, one way is to provide an event which the parent calls, such as ClassPermissionResult. So in the parent you need priva B4X: private sub B4xpage_permissionresult(Permission As String, Result As Boolean) if (xui.subexists(mysubclass,"Class_PermissionResult",2) then ' Call child Callsubdelayed3(mysubclass,"Class_PermissionResult",Permissions,result) end if end sub in the class you no have B4X: Private Sub BeginBLEscan rp_ble.CheckAndRequest(rp_ble.PERMISSION_ACCESS_FINE_LOCATION) Wait For Class_permissionResult (Permission As String, Result As Boolean) ' Wait for call from parent If Result = False Then ToastMessageShow("Permesso Bluetooth non fornito", True) Return End If End Sub
M Mike1970 Well-Known Member Licensed User Longtime User Jun 5, 2022 #6 Andrew (Digitwell) said: There is no simple way to do this. However, one way is to provide an event which the parent calls, such as ClassPermissionResult. So in the parent you need priva B4X: private sub B4xpage_permissionresult(Permission As String, Result As Boolean) if (xui.subexists(mysubclass,"Class_PermissionResult",2) then ' Call child Callsubdelayed3(mysubclass,"Class_PermissionResult",Permissions,result) end if end sub in the class you no have B4X: Private Sub BeginBLEscan rp_ble.CheckAndRequest(rp_ble.PERMISSION_ACCESS_FINE_LOCATION) Wait For Class_permissionResult (Permission As String, Result As Boolean) ' Wait for call from parent If Result = False Then ToastMessageShow("Permesso Bluetooth non fornito", True) Return End If End Sub Click to expand... Hi , thanks for the suggestion. but in this case, if the sub does not exists, the xui.subexists will fail. i don’t have to create a sub in the class, because I need it only in the “wait for” construct… I need to intercept it inside a function… so it must be not declared as a function (I think) I don’t know if I explained it very well Upvote 0
Andrew (Digitwell) said: There is no simple way to do this. However, one way is to provide an event which the parent calls, such as ClassPermissionResult. So in the parent you need priva B4X: private sub B4xpage_permissionresult(Permission As String, Result As Boolean) if (xui.subexists(mysubclass,"Class_PermissionResult",2) then ' Call child Callsubdelayed3(mysubclass,"Class_PermissionResult",Permissions,result) end if end sub in the class you no have B4X: Private Sub BeginBLEscan rp_ble.CheckAndRequest(rp_ble.PERMISSION_ACCESS_FINE_LOCATION) Wait For Class_permissionResult (Permission As String, Result As Boolean) ' Wait for call from parent If Result = False Then ToastMessageShow("Permesso Bluetooth non fornito", True) Return End If End Sub Click to expand... Hi , thanks for the suggestion. but in this case, if the sub does not exists, the xui.subexists will fail. i don’t have to create a sub in the class, because I need it only in the “wait for” construct… I need to intercept it inside a function… so it must be not declared as a function (I think) I don’t know if I explained it very well
Erel B4X founder Staff member Licensed User Longtime User Jun 6, 2022 #7 The permission result event is an activity event. It is delegated from the main activity to the relevant page (see the code in the main activity). You will need to delegate it from the page to your class as in @Andrew (Digitwell) answer. Upvote 0
The permission result event is an activity event. It is delegated from the main activity to the relevant page (see the code in the main activity). You will need to delegate it from the page to your class as in @Andrew (Digitwell) answer.