Hi B4A, I try to make an app which uses Xmpp with asmack library.
I can connet to server, get or send message. App is stable with xmpp.
When phone/cpu goes deep sleep. I can get messages and run media player to make alarm but i can't open my application with;
XmppService:
I run this code in my XmppService Module and cannot open app
My another problem is I wants to ping my server to learn is it achievable when device in deep sleep. So i tried
XmppServerPing Servce Module :
XmppService.objXmpp.BaglantiVarMi is my xmpp libraries function it pings to server and return true or false to my
pingBaglantiHatasi function in XmppService
Where i m wrong or what may i do ? Thanks.
I can connet to server, get or send message. App is stable with xmpp.
When phone/cpu goes deep sleep. I can get messages and run media player to make alarm but i can't open my application with;
XmppService:
B4X:
Sub Process_Globals
Dim p As PhoneWakeState
End Sub
Sub OpenApp
Try
If main_status = False Then
StartActivity(Panel)
p.KeepAlive(True)
End If
Catch
Log(LastException)
End Try
End Sub
Sub pingBaglantiHatasi(varmi As Boolean)
If varmi = True Then
OpenApp
sescal
End If
End Sub
I run this code in my XmppService Module and cannot open app
My another problem is I wants to ping my server to learn is it achievable when device in deep sleep. So i tried
XmppServerPing Servce Module :
B4X:
Sub Service_Start (StartingIntent As Intent)
XmppService.objXmpp.BaglantiVarMi
'StartServiceAt("", DateTime.Now+15*1000, True)
'StartServiceAtExact("",DateTime.Now+15*1000,True)
'SetExactAndAllowWhileIdle(DateTime.Now+15*1000,"XmppServerPing")
SetAlarm(DateTime.Now+30*1000)
End Sub
'Sub SetExactAndAllowWhileIdle (Time As Long, ServiceName As String)
' Dim p As Phone
' If p.SdkVersion < 23 Then
' StartServiceAtExact(ServiceName, Time, True)
' Else
' Dim in As Intent
' in.Initialize("", "")
' in.SetComponent(Application.PackageName & "/." & ServiceName.ToLowerCase)
' Dim jin As JavaObject = in
' jin.RunMethod("setAction", Array(Null))
' Dim ctxt As JavaObject
' ctxt.InitializeContext
' Dim am As JavaObject = ctxt.RunMethod("getSystemService", Array("alarm"))
' Dim pi As JavaObject
' pi = pi.InitializeStatic("android.app.PendingIntent").RunMethod("getService", _
' Array(ctxt, 1, in, 134217728))
' am.RunMethod("setExactAndAllowWhileIdle", Array(0, Time, pi))
' End If
'End Sub
Sub SetAlarm(timeToAlarm As Long)
'declare variable for java object
Dim srvAt As JavaObject
'call the function
srvAt.InitializeContext
srvAt.RunMethod("StartServiceAtExactWhileIdle", Array(timeToAlarm, True))
End Sub
#If JAVA
//import android.app.Service;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
public void StartServiceAtExactWhileIdle(Long time, Boolean wakeUp){
AlarmManager alMan = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this.getApplicationContext(), this.getClass());
PendingIntent penInt = PendingIntent.getService(this.getApplicationContext(), 1, intent, 134217728);
alMan.setExactAndAllowWhileIdle(wakeUp?AlarmManager.RTC_WAKEUP:AlarmManager.RTC, time, penInt);
}
#End If
XmppService.objXmpp.BaglantiVarMi is my xmpp libraries function it pings to server and return true or false to my
pingBaglantiHatasi function in XmppService
Where i m wrong or what may i do ? Thanks.