Android Question Intercept Running App

MarcoRome

Expert
Licensed User
Longtime User
Can i intercept the apps running?
Example i an app that the package is called "com.veniceartxxx" it is possible to obtain a service that when i run this app the same is intercepts
Thank you
Regards
Marco
 

MarcoRome

Expert
Licensed User
Longtime User
Hi Erel thank you for your answer.
With this code i can resolve this issue:

B4X:
Dim OS As OperatingSystem : OS.Initialize("OS")
Dim ProcessName, PIDs, NamePIDs, RunningApps As List
ProcessName.Initialize : PIDs.Initialize : NamePIDs.Initialize : RunningApps.Initialize
RunningApps = OS.RunningServiceInfo(500, ProcessName, PIDs, NamePIDs)

        For i = 0 To ProcessName.Size - 1
        Dim cerca As String = ProcessName.Get(i)
                'Here part name package that you want know if run
                If cerca.Contains("venice") Then
                    Dim nome_pacchetto As String = ProcessName.Get(i)
                    If Starter.primo_tempo = False Then
                        ToastMessageShow("Found Running App", False)
                    End If
                Else
'.............

                       
                   
                End If
   
        Next

End Sub

Another alternative is THIS

...On Lollipop and higher you'd use UsageStats to determine if an app is running:

UsageStatsManager usageStatsManager =(UsageStatsManager)getSystemService(USAGE_STATS_SERVICE);Calendar cal =Calendar.getInstance();
cal.add(Calendar.YEAR,-1);long start = cal.getTimeInMillis();longend=System.currentTimeMillis();List<UsageStats> queryUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, start,end);for(UsageStats stats : queryUsageStats){Log.e("TAG","Usage stats for: "+ stats.getPackageName());}

requires:

<uses-permissionandroid:name="android.permission.PACKAGE_USAGE_STATS"/>

Any idea to convert this code in B4A ?
Thank you
Marco
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You need to write a lib for it
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Hi all.
I have the follow problem.
if i run this code ( look also #3 )
B4X:
....
RunningApps = OS.RunningServiceInfo(500, ProcessName, PIDs, NamePIDs)
....
I have correct result:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
~w:1004,main,52
** Activity (main) Resume **
** Service (service_intercetta) Create **
** Service (service_intercetta) Start **
com.android.bluetooth : 7441
com.dropbox.android : 30829
com.google.android.gms : 5875
com.samsung.ucs.agent.boot : 5960
com.samsung.android.widgetapp.briefing : 5632
com.android.phone : 5830
com.google.android.music:main : 0
kill.applock : 648
com.microsoft.skydrive : 17542
com.sec.android.inputmethod : 30812
com.samsung.overmob.mygalaxy : 30594
com.microsoft.skydrive : 17542
com.android.systemui : 5275
com.android.bluetooth : 7441
com.microsoft.skydrive : 17542
......

But if i use this code:

B4X:
RunningApps = OS.RunningAppProcessInfo(ProcessName, PIDs, NamePIDs)

upload_2016-10-26_9-45-13.png


i have this result:

com.mytest : 4425

Only name my package without another process.


I try also this code:
B4X:
...
OS.RunningAppProcess
....


upload_2016-10-26_9-46-3.png


i have this result:
android.app.ActivityManager$RunningAppProcessInfo@a9fc4cd

Now, for all Master and colleagues the question is:
Can i know a list of apps that are turning on the device ??

Another App ( as this EXAMPLE APP ) work without problem also with Android 6

Thank you
Regards
Marco
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
MarcoRome,
Did you ever figure this out? I need the same capability.
Rusty
 
Upvote 0
Top