Hi all,
I'm trying (only trying ...) to develop a small application that would allow to take a picture with the internal camera when the device is pin locked.
I fully succeed to make the phone vibrate after a double press on the power button (power off, wait to go to sleep, then power ON, power OFF in less than 2 sec, this makes the phone vibrate).
Now I would want to add some code in order to take a picture in place of phone vibrate...)
For this, I've cut and pasted the cameraex example but I get this exception :
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (CallSubDelayed - TakePicture)
running waiting messages (1)
cameraexclass_takepicture (B4A line: 102)
cam.TakePicture
java.lang.RuntimeException: Method called after release()
at android.hardware.Camera.native_takePicture(Native Method)
at android.hardware.Camera.takePicture(Camera.java:1103)
at android.hardware.Camera.takePicture(Camera.java:1048)
at anywheresoftware.b4a.objects.CameraW.TakePicture(CameraW.java:287)
at test.power.cameraexclass._takepicture(cameraexclass.java:1130)
at test.power.main._takepicture(main.java:653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.keywords.Common$5$1.run(Common.java:943)
at anywheresoftware.b4a.BA.setActivityPaused(BA.java:382)
at test.power.main$ResumeMessage.run(main.java:252)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
here is the service code : the service takes the picture with callsubdelay...
what I am missing ?
thanks
Alain
I'm trying (only trying ...) to develop a small application that would allow to take a picture with the internal camera when the device is pin locked.
I fully succeed to make the phone vibrate after a double press on the power button (power off, wait to go to sleep, then power ON, power OFF in less than 2 sec, this makes the phone vibrate).
Now I would want to add some code in order to take a picture in place of phone vibrate...)
For this, I've cut and pasted the cameraex example but I get this exception :
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (CallSubDelayed - TakePicture)
running waiting messages (1)
cameraexclass_takepicture (B4A line: 102)
cam.TakePicture
java.lang.RuntimeException: Method called after release()
at android.hardware.Camera.native_takePicture(Native Method)
at android.hardware.Camera.takePicture(Camera.java:1103)
at android.hardware.Camera.takePicture(Camera.java:1048)
at anywheresoftware.b4a.objects.CameraW.TakePicture(CameraW.java:287)
at test.power.cameraexclass._takepicture(cameraexclass.java:1130)
at test.power.main._takepicture(main.java:653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.keywords.Common$5$1.run(Common.java:943)
at anywheresoftware.b4a.BA.setActivityPaused(BA.java:382)
at test.power.main$ResumeMessage.run(main.java:252)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
here is the service code : the service takes the picture with callsubdelay...
B4X:
Sub Process_Globals
Dim TimerService As Timer
Dim Counter As Int
Counter=0
' Dim p As Phone
Dim Vibrate As PhoneVibrate
Dim PE As PhoneEvents
Dim mydate As Long
Dim sNotif As Notification
End Sub
Sub Service_Create
' TimerService.Initialize("TimerService",1000)
' TimerService.Enabled=True
PE.Initialize("PE")
sNotif.Initialize
sNotif.Icon = "icon"
sNotif.SetInfo("MyApp","Service Running",Main)
sNotif.Sound = False
sNotif.Notify(1)
Service.StartForeground(1,sNotif)
End Sub
Sub Service_Start
' Counter=Counter+1
End Sub
Sub TimerService_Tick
' StartServiceAt("", DateTime.Now, True)
End Sub
Sub PE_ScreenOff (Intent As Intent)
If CheckLock Then ' si le tel est verouillé ...
If DateTime.Now - mydate < 2000 Then
Vibrate.Vibrate(200)
' <============ add the camera take picture here
CallSubDelayed(Main , "TakePicture")
End If
End If
' Log ("screen off")
mydate = DateTime.Now
End Sub
Sub PE_ScreenON (Intent As Intent)
'Log ("screen on")
mydate = DateTime.Now
End Sub
Sub CheckLock As Boolean ' permet de tester l'etat locked ou non du téléphone
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "keyguard", "java.lang.String")
Return r.RunMethod("inKeyguardRestrictedInputMode")
End Sub
what I am missing ?
thanks
Alain