监视当前运行的应用 [英] Monitor Currently Running Application

查看:72
本文介绍了监视当前运行的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了,我不能没有解决暂时的问题。
的code的目的是要监视的应用程序是在当前时刻运行。
我用下面的code和记录所产生的包名称,它的工作。

I am encountering a problem that i can't not solve for the moment.
The purpose of the code is to monitor which applications are running at current moment.
I used the following code and logged the resulting package name, it worked.

ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);  
String packageName = am.getRunningTasks(1).get(0).topActivity.getPackageName();  
Log.i("TTWYMonitor", packageName);

但我用code在的BroadcastReceiver ,什么都没有发生。 在清单,我宣布意图接收器安卓。NAME =MonitorApplication
我该怎么办呢? 请给出任何建议。

But I use that code in a BroadcastReceiver, nothing happened. In manifest,I declared an intent receiver android:name=".MonitorApplication.
What should I do, then? Please give any suggestion.

Yahel :谢谢,对不起我的非正式的问题。

Yahel : Thanks and sorry for my informal question.

推荐答案

更​​换活动,在getSystemService的参数有背景:

replace the "Activity" in getSystemService's parameters with "Context":

ActivityManager  manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

我测试了它,并为我工作得很好!

I tested it and works fine for me!

这篇关于监视当前运行的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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