Ciao a tutti, dopo tanto mi sto rimettendo a fare qualcosa con B4A, nel frattempo mi sono dimenticato quel poco che avevo imparato
Sto giocando un po' con l'sms interceptor e con la fotocamera, ma c'è qualcosa che mi sfugge.
La classe Camera dovrebbe generare un evento Camera_Ready che però mi sembra non venga proprio intercettato.
Il codice che ho scritto, intercetta un sms in arrivo e apre una activity che dovrebbe in automatico scattare una foto, ma non lo fa
Questo è il codice:
Main
Starter (Servizio)
TakePicture
Di conseguenza, nemmeno Camera1_PictureTaken viene intercettato.
Questi invece sono gli errori che vengono riportati:
Dove sto sbagliando?
Grazie.
Stefano
Sto giocando un po' con l'sms interceptor e con la fotocamera, ma c'è qualcosa che mi sfugge.
La classe Camera dovrebbe generare un evento Camera_Ready che però mi sembra non venga proprio intercettato.
Il codice che ho scritto, intercetta un sms in arrivo e apre una activity che dovrebbe in automatico scattare una foto, ma non lo fa
Questo è il codice:
Main
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("MainGabbia")
StartService(Starter)
Activity.Finish
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Starter (Servizio)
B4X:
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
Dim si As SmsInterceptor
Dim tts1 As TTS
' Dim pc As PhoneCalls
End Sub
Sub Service_Create
si.Initialize2("si", 999)
tts1.Initialize("tts1")
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt("", DateTime.Now + 0.1 * DateTime.TicksPerMinute, False)
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub
Sub si_MessageReceived (From As String, Body As String) As Boolean
If Body="parla" Then
tts1.Speak("Messaggio ricevuto da: " & From & Body, True)
End If
StartActivity(TakePicture)
Return True 'con questa istruzione si ritorna direttamente al chiamante senza inoltrare il messaggio al sistema
End Sub
TakePicture
B4X:
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
Dim camera1 As Camera
Dim Panel1 As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("PhotoLayout")
camera1.Initialize(Panel1, "Camera1")
' camera1.StartPreview'
'camera1.AutoFocus
'camera1.TakePicture
'Activity.Finish
End Sub
Sub Activity_Resume
camera1.Initialize(Panel1, "Camera1")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
camera1.Release
End Sub
Sub Camera1_Ready (Success As Boolean)
'camera1.Initialize(Panel1, "Camera1")
camera1.StartPreview
camera1.AutoFocus
camera1.TakePicture
If Success Then
camera1.StartPreview
Else
ToastMessageShow("Cannot open camera.", True)
End If
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
Di conseguenza, nemmeno Camera1_PictureTaken viene intercettato.
Questi invece sono gli errori che vengono riportati:
Dove sto sbagliando?
Grazie.
Stefano