Determine whether a particular program or service is running as a process!

Amalkotey

Active Member
Licensed User
Longtime User
Hello,

is a way to see fixed, run the programs and services on the Android device, so I can display this information in a ListView? Thank you for your help in advance.
 

madSac

Active Member
Licensed User
Longtime User
IsPaused("Service_Name")
It returns false if service is running and true if it is not running.
 
Upvote 0

Amalkotey

Active Member
Licensed User
Longtime User
@madSac: Thanks for the info, but unfortunately does ispaused only in their own program.

@Erel: Thanks for the info. With the following code I have tried to get a listing.

B4X:
   Log("Start")
      Dim Tasks As List
      Tasks = OS.getRunningTasks(1000)
      If Tasks.Size > 0 Then
         For i = 0 To Tasks.Size - 1
            Log(Tasks.Get(i))
         Next
      End If
      Msgbox("Hier", "Test")

There were, however, not identified any processes. What is wrong with the code?

Edit: Below the log output from the above program code:

B4X:
Tasks.Size=3
android.app.ActivityManager$RunningTaskInfo@41a0c770
android.app.ActivityManager$RunningTaskInfo@41a0c7a0
android.app.ActivityManager$RunningTaskInfo@41a4b158

I need a way to determine if, for example, the program MagicLocker (Package: mobi.lockscreen.magiclocker) is active and running. For suggestions on how to realize the ish, I would be grateful.
 
Last edited:
Upvote 0

Amalkotey

Active Member
Licensed User
Longtime User
You will need to use Reflection to extract information from this object.

Thanks for the info, Erel. I would like you to show me how I need to formulate the query with the Reflector Library. Unfortunately I have no idea how I should build this. Thank you for your help.
 
Upvote 0

Amalkotey

Active Member
Licensed User
Longtime User
Thanks for the help. Where can I get more information about the fields that I can read with GetField?
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
Dear Erel,

Thanks a lot. I also can learn a lot from what is discussed here by you and Amalkotey.

Based on this topic, I tried and want to see if the user is currently opening and working with Phonebook (Contacts). I used your codes with Reflector, but instead of getting the Field "BaseActivity", I get "TopActivity" and can get the Log as below:

ComponentInfo{com.sonyericsson.android.socialphonebook/com.sonyericsson.android.socialphonebook.DialerEntryActivity}

I guess the following com.sonyericsson.android.socialphonebook.DialerEntryActivity is specific only for SONY phone (I am using SONY phone for test).

Just quick question, is there any way to know that User is opening and working with Contacts in general (for all Android phone).

Hope my queston is still related to this topic so I don't need to create a new thread for.

Thanks & Regards,
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
First of all this is a good solution that I previously missed...

You can use PackageManager.QueryIntentActivities and find all the activities that can view a contact.
Try this code:
B4X:
   Dim pm As PackageManager
   Dim i As Intent
   i.Initialize(i.ACTION_VIEW, "content://contacts/people/1")
   Log(pm.QueryIntentActivities(i))
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
First of all this is a good solution that I previously missed...

You can use PackageManager.QueryIntentActivities and find all the activities that can view a contact.
Try this code:
B4X:
   Dim pm As PackageManager
   Dim i As Intent
   i.Initialize(i.ACTION_VIEW, "content://contacts/people/1")
   Log(pm.QueryIntentActivities(i))

Hi Erel,

Many thanks for your answer and solution. I think I am going to the right direction with using intent and very near to a good solution for that.

But I think I still miss something. In PackageManager I cannot find out QueryIntentActivities, but only the followings:

- GetApplicationIcon
- GetApplicationIntent
- GetApplicationLabel
- GetInstalledPackages
- GetVersionCodes
- GetVersionName

So I decided to try with GetApplicationIntent. My codes are as follows:

B4X:
Dim pm As PackageManager
Dim myintent As Intent
myintent.Initialize(myintent.ACTION_VIEW, "content://contacts/people/1")
Log("THIS IS MY LOG " & pm.GetApplicationIntent(myintent))

Below is the Log (first row is Log from OS Library showing that I already opened Contacts).
The last row in Log is from PackageManager, showing that "Not initialized". What's wrong or I missed something?

B4X:
ComponentInfo{com.sonyericsson.android.socialphonebook/com.sonyericsson.android.socialphonebook.DialerEntryActivity}
ComponentInfo{se.brokenbrain.drawer/se.brokenbrain.drawer.Drawer}
ComponentInfo{adcvn.no1smsblocker/adcvn.no1smsblocker.main}
ComponentInfo{com.android.phone/com.android.phone.SomcInCallScreen}
THIS IS MY LOG (Intent) Not initialized

Once again thank you.

UPDATE:

I updated the Phone Library and now can get it work. The Log is like this:

THIS IS MY LOG (ArrayList) [com.sonyericsson.infiniteview/.ui.InfiniteViewActivity]

It seems that I got same log all the times, even when the Contacts went to background or even when I manually killed it.
I think (maybe I am wrong) this solution can help to check if such Activities intent do exist or not, regardless it is currently used or not used by the user. Hence it cannot help me to check whether the Contacts is really running and used by the user?
 
Last edited:
Upvote 0
Top