Is a process running ?

Gary Miyakawa

Active Member
Licensed User
Longtime User
I have an app that needs to make sure a different app is running in the tablet before I ask it to do something. The app in question has no API so I need to see if it's in the task list... On straight Android coding, it's called isNamedProcessRunning but I'm not finding a similar capability with B4A.

I'm sure it's there, I just can't find it.

Suggestions ?

Thanks,

Gary M
 

Gary Miyakawa

Active Member
Licensed User
Longtime User
Excellent! I don't know why my searches didn't come up with that posting.

EDIT... That's a link to something that works with Windows mobile... I'm on the Android side of the house (and it doesn't look like it works over here...)

Thanks anyway !

Gary M
 
Last edited:
Upvote 0

raytronixsystems

Active Member
Licensed User
Longtime User
:sign0161:
Sorry about that! I was wondering why the code used the "shell" keyword which I had never seen in b4a code before.

I'm sure somebody up here has your answer. Good Luck!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code from B4A-Bridge searches for a running process using 'ps' command:
B4X:
Sub KillProgram (Package As String)
   Dim sb As StringBuilder
   sb.Initialize
   Phone.Shell("ps", Null, sb, Null)
   Dim m As Matcher
   m = Regex.Matcher2("^[^ ]*\s+(\d+) .*" & package, Regex.MULTILINE, sb.ToString)
   If m.Find Then
      Log("Package found: " & package)
      ...
   End If
End Sub
 
Upvote 0

Gary Miyakawa

Active Member
Licensed User
Longtime User
Erel,

That does exactly what you described. Getting all the Processes.. BUT (why does there always have to be a but.. ;) )

When I run the code, I'm getting back 86/87 processes but none of them appear to be the process I'm looking for. I know it's loaded up/running because there is a matching icon on the bottom task bar of the display..

I even booted the Tablet, ran the program, looked at the ps count and then ran the new task (that should stay in the back ground) and ran ps again and it had the same value...

What am I missing here ? Doesn't the app have to be running to appear in the app list (and is the app list different (other than name) from the PS list) ?

Thanks again !

Gary M
 
Upvote 0

Gary Miyakawa

Active Member
Licensed User
Longtime User
Actually, I'm looking at the bottom of the screen on the Galaxy Tab 2 (running 4.0 I believe) and there is a task bar at the bottom of the screen that implies my "other" app is running.

When I run my app and do an intent on the other app, everything works fine so I know that the "other" app is out there ready to run. I've tried my app with the "other" app not having been started and my app fails (as would be expected)..

What I'm trying to do is, before I launch the intent for the "other" app, I make sure it's running on the tablet.

The "other" app is a video conferencing app with VERY little API tools available to me to test it's state.

Thanks,

Gary M
 
Upvote 0

Gary Miyakawa

Active Member
Licensed User
Longtime User
My intent starts a standards based video conference call. The code is as follows.
B4X:
Dim i As Intent
i.Initialize("com.acme.mobile.android.intent.VIDEO_CALL", "")
i.PutExtra("acme.videocall.dialnumber", swork)
i.PutExtra("acme.videocall.calltype", CallType)
   
i.PutExtra("acme.videocall.callrate", "384")

Dim p As Phone 'phone library
p.SendBroadcastIntent(i)

The code works most of the time (and does start the other app) but "sometimes" it doesn't so I was trying to see if I could "test" to see if it really did get started.


Thanks,

Gary M
 
Upvote 0

Gary Miyakawa

Active Member
Licensed User
Longtime User
Their minimal documentation states:

Normally, you should broadcast an implicit intent to launch the video app

and their code example is:

B4X:
intent.putExtra(DIAL_NUMBER_NAME, dialNumber);
intent.putExtra(CALL_TYPE_NAME, protocol);
intent.putExtra(CALL_RATE_NAME, callRate);
sendBroadcast(intent);

So I would interpret that to mean I should be doing a broadcast intent.

Is that your impression too ?

Thanks,

Gary M
 
Upvote 0
Top