Hello all,
I am currently working on a camera+ftp application. The camera library needs to be run in an activity module rather than a service module. I am looking for the most appropriate method to suspend the activity module for a defined time (probably 20min) then re-awaken it, to allow the camera operation.
I have had some success with this using cron jobs, but it would be tidier to do it in the app itself.
My thought at the moment is t use a service module with a 15 min timer, then get it to re-awaken the activity module & allow it to operate the image capture by the camera lib.
The attached code works, but requires the user to manually take a picture and initiate the ftp upload by utton clicks.
Advice would be greatly appreciated.
Best wishes,
refsmmat
I am currently working on a camera+ftp application. The camera library needs to be run in an activity module rather than a service module. I am looking for the most appropriate method to suspend the activity module for a defined time (probably 20min) then re-awaken it, to allow the camera operation.
I have had some success with this using cron jobs, but it would be tidier to do it in the app itself.
My thought at the moment is t use a service module with a 15 min timer, then get it to re-awaken the activity module & allow it to operate the image capture by the camera lib.
The attached code works, but requires the user to manually take a picture and initiate the ftp upload by utton clicks.
Advice would be greatly appreciated.
Best wishes,
refsmmat
B4X:
Sub Process_Globals
Dim FTP As FTP
End Sub
Sub Globals
Dim camera1 As Camera
Dim btnTakePicture As Button
Dim Panel1 As Panel
Dim btn_upload As Button
Dim Button_Quit As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("argus_camera")
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 FTP_UploadCompleted(ServerPath As String, Success As Boolean)
Dim now As Long
now = DateTime.now
If Success Then
ToastMessageShow("UPLOAD COMPLETED!! " & (DateTime.Time(now)), True)
Else
ToastMessageShow("ACK UPLOAD FAILED!!!", 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 Button_Quit_Click
Activity.Finish
End Sub
Sub Camera1_PictureTaken (Data() As Byte)
camera1.StartPreview
Dim out As OutputStream
out = File.OpenOutput(File.DirRootExternal, "1.jpg", False)
out.WriteBytes(Data, 0, Data.Length)
out.Close
ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal, "1.jpg"), True)
btnTakePicture.Enabled = True
End Sub
Sub btnTakePicture_Click
btnTakePicture.Enabled = False
camera1.TakePicture
End Sub
Sub btn_upload_Click
File_upload
End Sub
Sub File_upload
Dim now As Long
now = DateTime.now
'lblSatellites.Text = "file upload sub start"
If File.Exists (File.DirRootExternal, "1.jpg") Then
FTP.Initialize("FTP", "myftpserver.xyz", 21, "[email protected]", "password")
FTP.PassiveMode = True
If FTP.IsInitialized Then
FTP.UploadFile (File.DirRootExternal, "1.jpg", False, "/img/" & (DateTime.GetYear(now)) & "-" & (DateTime.GetMonth(now))& "-" & (DateTime.GetDayOfMonth(now)) & "_" & (DateTime.GetHour(now)) & "_" & (DateTime.GetMinute(now))& "_" & (DateTime.GetSecond(now))& ".jpg")
FTP.Close
ToastMessageShow("File upload attempted at " & (DateTime.Time(now)), True)
End If
End If
End Sub