Android Question Activity Loading externals app's

scsjc

Well-Known Member
Licensed User
Longtime User
Hello,

I want make service intercept when a user load a program, for that i'm use PackageName insisde of a service.

Now i use StartServiceAt every 500ms and look if the program is load, and when screenoff (PhoneEvents library) change to high 6000ms and comingback screenon change to 500ms. But that use a hi battery. (before that im use timer, but the people kill all process and finaly the timer)

is possible have a activity user when user touch screen or doing anything with phone ???
 
Last edited:

scsjc

Well-Known Member
Licensed User
Longtime User
Why do you need to call StartServiceAt every 500ms? Use a foreground service instead (with StartServiceAt every few minutes).

I restart every 500ms, because when push button kill proceses finally. and i think making startserviceat every time fix that.
I'm try to make a LookingAPP, (when user load "xxx app") the program lock phone...
i show my code, and upload a sample.
what you think??? Thanks.
(Sorry for my english)



B4X:
#Region  Service Attributes
    #StartAtBoot: true
    #StartCommandReturnValue: android.app.Service.START_STICKY
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim ActMan As JavaObject
      Dim R As Reflector
    Dim versionandroid As String
    Dim locked As Boolean = True
    Dim lowtime = 5000, hitime = 10000, curtime=5000 As Int
    Dim PackageName As String
    Dim PE As PhoneEvents
    Dim screenoff As Boolean=False
    Dim SF As StringFunctions
End Sub


Sub Service_Create
    Log("createservice")
    PE.Initialize("PE")

    'get version android
    R.Target=R.GetContext
    ActMan = R.RunMethod2("getSystemService","activity","java.lang.String")
    versionandroid=R.GetStaticField ("android.os.Build$VERSION", "RELEASE")
End Sub

Sub Service_Start (StartingIntent As Intent)
    Log("startservice")
    StartServiceAt("", DateTime.Now + curtime, True)

    If SF.Left(versionandroid,1)>=5 Then
        Dim TaskInfo As JavaObject = ActMan.RunMethod("getRunningAppProcesses",Array As Object())
        Dim CompInfo As JavaObject = TaskInfo.RunMethodJO("get",Array As Object(0))
        PackageName = CompInfo.GetField("processName")
    Else  
        Dim TaskInfo As JavaObject = ActMan.RunMethod("getRunningTasks",Array As Object(1))
        Dim CompInfo As JavaObject = TaskInfo.RunMethodJO("get",Array As Object(0)).GetField("topActivity")
        PackageName = CompInfo.RunMethod("getPackageName",Null)
    End If

    Log(PackageName&" estado: "&locked & "intervalo: "&curtime)
    ToastMessageShow(PackageName&" estado: "&locked & "intervalo: "&curtime,False)  

End Sub

Sub Service_Destroy
End Sub




Sub PE_ScreenOn (Intent As Intent)
    Log("ScreenOn")
    curtime=lowtime
    StartServiceAt("", DateTime.Now + curtime, True)
    locked=True
    screenoff=False
End Sub
Sub PE_ScreenOff (Intent As Intent)
    Log("ScreenOff")
    curtime=hitime*60
    locked=True
    screenoff=True
End Sub
Sub PE_UserPresent (Intent As Intent)
    Log("UserPresent")
End Sub
 

Attachments

  • servicio app.zip
    361.1 KB · Views: 140
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
Which button kills the process?
In samsung 5, when you push recent task (multitasking button), can you kill all processes, (right key option).

For that reason I change the code. In the first time I make with a timer, but this key kill proces.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…