D
D
DivelNick2016-09-05 18:01:41
Java
DivelNick, 2016-09-05 18:01:41

How to get the name of the running application?

I am writing a service, it needs to get the name of the application that is running on the device, how can this be implemented?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
DivelNick, 2016-10-02
@DivelNick

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List runningAppProcessInfo = am.getRunningAppProcesses();
for (int i = 0; i < 10 /*runningAppProcessInfo.size()*/; i++) {
Log.i("process"," process number "+i +" name "+runningAppProcessInfo.get(i).processName );
}
If you test this code, you can see that the zero element of runningAppProcessInfo will be the name of the process that belongs to the application that is active at the given time.

R
Rou1997, 2016-09-05
@Rou1997

Run a bash command ps(run the ps application), get a list of processes, then get the name of the package, though the presence of a process does not mean that the application is running, and even more so that one of the Activities is open, but if there is no process, then it is definitely not running, there are other ways,
google: android java get all working applications

Z
z0rgoyok, 2016-09-05
@z0rgoyok

Look here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question