Android Question I copied the source code for camera but not working

rogel a. tolentino

Member
Licensed User
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: Camera example
#VersionCode: 1
#VersionName:
#SupportedOrientations: landscape
#End Region

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
Dim camera1 As Camera
Dim btnTakePicture As Button
Dim Panel1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("11")
End Sub
Sub Camera1_Ready (Success As Boolean)
If Success Then
camera1.StartPreview
btnTakePicture.Enabled = True
Else
ToastMessageShow("Cannot open camera.", True)
End If
End Sub

Sub Activity_Resume
btnTakePicture.Enabled = False
camera1.Initialize(Panel1, "Camera1")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
camera1.Release
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
camera1.StartPreview
Dim out As OutputStream
out = File.OpenOutput(File.DirRootExternal, "1q.jpg", False)
out.WriteBytes(Data, 0, Data.Length)
out.Close
ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal, "1q.jpg"), True)
btnTakePicture.Enabled = True
'Msgbox(2,2)
End Sub

Sub btnTakePicture_Click
btnTakePicture.Enabled = False
'Msgbox(1,1)
camera1.TakePicture
End Sub
 

rogel a. tolentino

Member
Licensed User
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" />
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

That is the content of manifest from downloaded code which is no error

The manifesr created by jyst copying the source code from camera are shown below
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Check runtimerpwemissions library, and modify your last code:
B4X:
Sub btnTakePicture_Click
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    wait for Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result=True Then
        btnTakePicture.Enabled = False
        'Msgbox(1,1)
        camera1.TakePicture
    End If
End Sub
 
Upvote 0

rogel a. tolentino

Member
Licensed User
Check runtimerpwemissions library, and modify your last code:
B4X:
Sub btnTakePicture_Click
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    wait for Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result=True Then
        btnTakePicture.Enabled = False
        'Msgbox(1,1)
        camera1.TakePicture
    End If
End Sub
Still not working
 
Upvote 0

rogel a. tolentino

Member
Licensed User
the pict is my source while the camera example is my downloaded code which is working. Pls help me to find what is wrong in pict project, Thanks
 

Attachments

  • CameraExample.zip
    5.7 KB · Views: 76
Upvote 0

rogel a. tolentino

Member
Licensed User
cameraexample is the downloaded source code and running properly, pict.rar is the project does not run properly, I just made a copy and paste from cameraexample but dous not working. pls help me whats wrong in pict.rar. Thanks alot. Pls disregard my previous post. Those are incomplete
 

Attachments

  • pict.rar
    403.4 KB · Views: 68
  • CameraExample.zip
    5.7 KB · Views: 69
Upvote 0

rogel a. tolentino

Member
Licensed User
Never mind I already resolve.
I put the runtime permision as activity_resume

Sub Activity_Resume
btnTakePicture.Enabled = True 'False
camera1.Initialize(Panel1, "Camera1")
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_CAMERA)
wait for Activity_PermissionResult (Permission As String, Result As Boolean)
End Sub
 
Upvote 0
Top