iOS Question Camera permission

stevenindon

Active Member
Licensed User
Hello All, I have been using camera function to start the camera without fail. Below are my codes for camera,


B4X:
'**********************************
'CAMERA INTENT
'**********************************
Sub TW_Camera_Init(sPage As Page)
    Camera.Initialize("Camera",sPage)
End Sub

Sub TW_Camera_Exec(sPage As String,sWidth As Int,sHeight As Int)As ResumableSub
    TakePicture (sPage,sWidth, sHeight)
    Wait For Image_Available(Success As Boolean, bmp As B4XBitmap)
    If Success=True Then
        Return bmp
    Else if Success=False Then
        Dim TmpImg As B4XBitmap=LoadBitmap(File.DirAssets,"empty.png")
        Return TmpImg
    End If
End Sub

Private Sub TakePicture (sPage As String,TargetWidth As Int, TargetHeight As Int)
    Camera.TakePicture
    Dim TopPage As String = sPage
    Wait For Camera_Complete(Success As Boolean, Image As Bitmap, VideoPath As String)
    B4XPages.GetManager.mStackOfPageIds.Add(TopPage) 'this is required as the page will be removed from the stack when the external camera page appears.
    If Success Then
        Dim bmp As B4XBitmap = Image
        bmp.Resize(TargetWidth, TargetHeight, True)
        CallSubDelayed3(Me, "Image_Available", True, bmp)
    Else
        CallSubDelayed3(Me, "Image_Available", False, Null)
    End If
End Sub

I have been trying to catch user permission for camera... but i dont find any codes in this forum that solves that. How can i build a function to check camera access permission?
 

hatzisn

Well-Known Member
Licensed User
Longtime User
Here it is:

B4X:
    Dim rp as RuntimePermissions 'Include RuntimePermissions Library
    Dim bCamera as Boolean
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    wait for Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = True Then
        bCamera = True
    End If
 
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
Also, are you using camera2 interface?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Here it is:

B4X:
    Dim rp as RuntimePermissions 'Include RuntimePermissions Library
    Dim bCamera as Boolean
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    wait for Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = True Then
        bCamera = True
    End If
Runtimepermission is a android feature.


How can i build a function to check camera access permission?

do you want to check if your app has permission to use the camera?
when you try to take a picture the OS will ask for permission. if the user will deny then as far as i remember the "Success" variable in the Cam_Complete event will return FALSE.
 
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
Runtimepermission is a android feature.

Totally right. Sorry, my bad due to small screen. When answering in mobile with keyboard expanded I missed the top part defining the question as "iOS Question".
 
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
 
Upvote 0

stevenindon

Active Member
Licensed User
@hatzisn, I have found the same link but.... initially i was a little skeptical looking at the code which is so short.

After your above reminder, I gave it a try and indeed it worked.

Thanks hatzisn
 
Upvote 0
Top