如何找到当前正在运行的应用程序编程的机器人? [英] How to find the currently running applications programatically in android?

查看:189
本文介绍了如何找到当前正在运行的应用程序编程的机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新到Android。我工作的应用程序,必须获取有关当前应用前景上运行的信息。

这意味着,如果用户运行的所有应用程序,我的应用程序应该捕获启动的应用程序的信息,我的应用程序不应该中断启动的应用程序的时间。

例如:如果用户启动浏览器应用我的应用程序应该打印日志浏览器应用程序的信息。

我怎样才能做到这一点?

解决方案

  ActivityManager activity_manager =(ActivityManager)上下文
                .getSystemService(Activity.ACTIVITY_SERVICE);
 

ActivityManager 的方法 getRunningTasks(INT) ActivityManager 似乎是您正在寻找的解决方案。

 最后ActivityManager activityManager =(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
最后的名单,其中,RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE的);

的for(int i = 0; I< recentTasks.size();我++)
{
    Log.d(执行的应用程序,应用程序执行:+ recentTasks.get(I).baseActivity.toShortString()+\ t \ t ID:+ recentTasks.get(I).ID +);
}
 

另外,看看以下主题: 看到用户执行的Andr​​oid最近的任务

I am very new to Android. I am working on application that must get the information about the applications currently running on foreground.

It means if user launches any applications, my application should capture the launched application information, by the time my application shouldn't interrupt launched application.

Example: If user launches browser application my application should print browser application information on log.

How can I do this?

解决方案

ActivityManager activity_manager = (ActivityManager) context
                .getSystemService(Activity.ACTIVITY_SERVICE);

ActivityManager has method getRunningTasks(int). ActivityManager seems to be the solution you are searching for.

final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

for (int i = 0; i < recentTasks.size(); i++) 
{
    Log.d("Executed app", "Application executed : " +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: "+recentTasks.get(i).id+"");         
}

Also, have a look at following thread: See Android recent task executed by the user

这篇关于如何找到当前正在运行的应用程序编程的机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆