Hi,at the first time sorry for my english.
I´ve this code:
'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim inici As Timer
Dim tiempo As Timer
Dim temp As Timer
Dim alea As Int
Dim n As Notification
'Dim vibrar As Int
Dim dat As leerdatos
Dim nombre As String
Dim hora1 As String
Dim hora2 As String
Dim hora3 As String
Dim hora4 As String
Dim hora As Int
Dim sonido As String
Dim inth1 As Int
Dim inth2 As Int
Dim inth3 As Int
Dim inth4 As Int
Dim i As Int
Dim ct1 As CustomToast
Dim alerta As Bitmap
Dim hc As HttpClient
Dim posimagen As Int
End Sub
Sub Service_Create
'tiempo.Enabled=False
'ToastMessageShow("crea al servicio con vibrar "&vibrar,False)
n.Initialize
n.Icon="icon"
inici.Initialize("inici1",100)
inici.Enabled=True
End Sub
Sub Service_Start (StartingIntent As Intent)
nombre=dat.leernom
sonido=dat.sonidodat
hora1=dat.h1a
hora2=dat.h2a
hora3=dat.h3a
hora4=dat.h4a
inth1=hora1
inth2=hora2
inth3=hora3
inth4=hora4
posimagen=Rnd(1,50)
hora=DateTime.GetHour(DateTime.Now)
ct1.Initialize
alerta.Initialize(File.DirAssets,"alarma.jpg")
idmovil.vibras=0
'ToastMessageShow("sonido: "&sonido,False)
If idmovil.soni=0 Then
n.Sound=False
Else
n.Sound=True
End If
n.SetInfo(nombre, "A fichar " , idmovil)
n.Vibrate=True
'Change Main (above) to "" if this code is in the main module.
'n.Notify(1)
'StartServiceAt("",DateTime.Now+alea,True) '
ToastMessageShow(" servicio iniciado ",False)
End Sub
Sub inici1_Tick
'ToastMessageShow("inicio " &inth1& " " &"hora del movil"& hora,False)
If inth1<=hora AND hora<inth2 Then
alea=Rnd(1,5)
temp.Initialize("temp1",5000*alea)
temp.Enabled=True
Else If inth3<=hora AND hora<inth4 Then
alea=Rnd(3,10)
temp.Initialize("temp1",5000*alea)
temp.Enabled=True
End If
End Sub
Sub temp1_Tick
Service.StartForeground(1,n)
tiempo.Initialize("tiempo1",1000)
tiempo.Enabled=True
'StartActivity(idmovil)
'n.Notify(1)
'n.AutoCancel=True
ct1.ShowBitmap( "",1000,Gravity.FILL,10,10,alerta)
'tiempo1_Tick
i=i+1
End Sub
Sub tiempo1_Tick
i=i+1
If idmovil.vibras=1 Then
cancelvibrate
'n.Cancel(1)
Else If i=10 Then
cancelvibrate
Else
n.Vibrate=True
Vibrate(500,200)
End If
End Sub
Sub Vibrate(On As Long, Off As Long)
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "vibrator", "java.lang.String")
Dim pattern(2) As Long
pattern(0) = On
pattern(1) = Off
r.RunMethod4("vibrate", Array As Object(pattern, 0), Array As String("[J", "java.lang.int"))
End Sub
Sub cancelvibrate
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "vibrator", "java.lang.String")
r.RunMethod("cancel")
tiempo.Enabled=False
' ToastMessageShow("vibracion: "& i,False)
i=0
ExecuteRemoteQuery("http://192.168.1.33/android.php?hora1="& hora,1)
Service.StopForeground(1)
n.Cancel(1)
End Sub
Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
Dim req As HttpRequest
req.InitializePost2(Query, Query.GetBytes("UTF8"))
ToastMessageShow(Query,True)
hc.Execute(req, TaskId)
End Sub
Sub Service_Destroy
ToastMessageShow("servicio detenido",False)
End Sub
Run ok if timer is so small,but when i put 30 o more minutes then service stop.
I call the service from activity,first estop previous service an after call again.
Please can hellp me.
Thanks
I´ve this code:
'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim inici As Timer
Dim tiempo As Timer
Dim temp As Timer
Dim alea As Int
Dim n As Notification
'Dim vibrar As Int
Dim dat As leerdatos
Dim nombre As String
Dim hora1 As String
Dim hora2 As String
Dim hora3 As String
Dim hora4 As String
Dim hora As Int
Dim sonido As String
Dim inth1 As Int
Dim inth2 As Int
Dim inth3 As Int
Dim inth4 As Int
Dim i As Int
Dim ct1 As CustomToast
Dim alerta As Bitmap
Dim hc As HttpClient
Dim posimagen As Int
End Sub
Sub Service_Create
'tiempo.Enabled=False
'ToastMessageShow("crea al servicio con vibrar "&vibrar,False)
n.Initialize
n.Icon="icon"
inici.Initialize("inici1",100)
inici.Enabled=True
End Sub
Sub Service_Start (StartingIntent As Intent)
nombre=dat.leernom
sonido=dat.sonidodat
hora1=dat.h1a
hora2=dat.h2a
hora3=dat.h3a
hora4=dat.h4a
inth1=hora1
inth2=hora2
inth3=hora3
inth4=hora4
posimagen=Rnd(1,50)
hora=DateTime.GetHour(DateTime.Now)
ct1.Initialize
alerta.Initialize(File.DirAssets,"alarma.jpg")
idmovil.vibras=0
'ToastMessageShow("sonido: "&sonido,False)
If idmovil.soni=0 Then
n.Sound=False
Else
n.Sound=True
End If
n.SetInfo(nombre, "A fichar " , idmovil)
n.Vibrate=True
'Change Main (above) to "" if this code is in the main module.
'n.Notify(1)
'StartServiceAt("",DateTime.Now+alea,True) '
ToastMessageShow(" servicio iniciado ",False)
End Sub
Sub inici1_Tick
'ToastMessageShow("inicio " &inth1& " " &"hora del movil"& hora,False)
If inth1<=hora AND hora<inth2 Then
alea=Rnd(1,5)
temp.Initialize("temp1",5000*alea)
temp.Enabled=True
Else If inth3<=hora AND hora<inth4 Then
alea=Rnd(3,10)
temp.Initialize("temp1",5000*alea)
temp.Enabled=True
End If
End Sub
Sub temp1_Tick
Service.StartForeground(1,n)
tiempo.Initialize("tiempo1",1000)
tiempo.Enabled=True
'StartActivity(idmovil)
'n.Notify(1)
'n.AutoCancel=True
ct1.ShowBitmap( "",1000,Gravity.FILL,10,10,alerta)
'tiempo1_Tick
i=i+1
End Sub
Sub tiempo1_Tick
i=i+1
If idmovil.vibras=1 Then
cancelvibrate
'n.Cancel(1)
Else If i=10 Then
cancelvibrate
Else
n.Vibrate=True
Vibrate(500,200)
End If
End Sub
Sub Vibrate(On As Long, Off As Long)
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "vibrator", "java.lang.String")
Dim pattern(2) As Long
pattern(0) = On
pattern(1) = Off
r.RunMethod4("vibrate", Array As Object(pattern, 0), Array As String("[J", "java.lang.int"))
End Sub
Sub cancelvibrate
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "vibrator", "java.lang.String")
r.RunMethod("cancel")
tiempo.Enabled=False
' ToastMessageShow("vibracion: "& i,False)
i=0
ExecuteRemoteQuery("http://192.168.1.33/android.php?hora1="& hora,1)
Service.StopForeground(1)
n.Cancel(1)
End Sub
Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
Dim req As HttpRequest
req.InitializePost2(Query, Query.GetBytes("UTF8"))
ToastMessageShow(Query,True)
hc.Execute(req, TaskId)
End Sub
Sub Service_Destroy
ToastMessageShow("servicio detenido",False)
End Sub
Run ok if timer is so small,but when i put 30 o more minutes then service stop.
I call the service from activity,first estop previous service an after call again.
Please can hellp me.
Thanks