Android Question Camera not available

RishiKumar2210

Active Member
Hi All, I want to take picture using phone's camera and set it in an imageview. here is my code
B4X:
Sub TakePicture
    Dim i As Intent
    i.Initialize("android.media.action.IMAGE_CAPTURE", "")
    File.Delete(iprovide_fileprovider.SharedFolder, tempImageFile)
    Dim u As Object = iprovide_fileprovider.GetFileUri(tempImageFile)
    i.PutExtra("output", u) 'the image will be saved to this path
    Try
        StartActivityForResult(i)
    Catch
        ToastMessageShow("Camera is not available.", True)
        Log(LastException)
    End Try
End Sub

Sub ion_Event (MethodName As String, Args() As Object) As Object
    If Args(0) = -1 Then
        Try
            Dim in As Intent = Args(1)
            If File.Exists(iprovide_fileprovider.SharedFolder, tempImageFile) Then
                lastPicture = LoadBitmapSample(iprovide_fileprovider.SharedFolder, tempImageFile, 100%x, 100%y)
                is_imageextension = "jpg"
                Log("image extension : " & is_imageextension)
                                
                Dim v As B4XView = ix_xui.CreatePanel("")
                v.SetLayoutAnimated(0,100%x,100%y,90%x, 80%y)
                v.LoadLayout("cropimage_dialog")

                id_cropimagedialog.BorderWidth = 1dip
                id_cropimagedialog.BorderCornersRadius = 7dip
                id_cropimagedialog.BackgroundColor = Colors.aRgb(255,255,255,255)
    
                id_cropimagedialog.ShowCustom(v, "", "", "")
    
                ResetUserFontScale(v)
                ip_cropimagepanel.Visible = False
                ip_notcropimagepanel.Visible = True

                image_notcropimage.Bitmap = lastPicture
            Else If in.HasExtra("data") Then
                Dim jo As JavaObject = in
                lastPicture = jo.RunMethodJO("getExtras", Null).RunMethod("get", Array("data"))
            End If
        Catch
            Log(LastException)
        End Try
    End If

    Return Null
End Sub

Sub StartActivityForResult(intent As Intent)
    Dim jo As JavaObject = GetBA
    iobj_object = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(iobj_object, intent))
End Sub

Sub GetBA As Object
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetField("processBA")
End Sub
This code works perfectly in Activities. but not working in B4XPages. it says "camera is not available". how to overcome this?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…