怎么办Android的显示器使用应用程序的工作 [英] how do android monitor usage applications work

查看:156
本文介绍了怎么办Android的显示器使用应用程序的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写日志我的手机上的其他应用程序使用情况的应用程序。
因此,例如,我得到我已经进入Facebook的时代。

I want to write an application that logs the usage of other applications on my phone.
So for example I get the times I have entered Facebook.

据我所知是没有办法让一个BroadcastReceiver每一次Facebook的开始醒来。 另一种方法是有一个一直在后台运行,并检查正在运行的应用,并进入睡眠状态每秒左右的服务,但我想这会耗尽我的电池快。

I understand there is no way to get a broadcastreceiver to wake up every time Facebook starts. Another way is to have a service that always runs in the background and checks for running apps and goes to sleep every second or so, but I guess this will drain my battery faster.

那么,什么是最好的办法可以这样做?有一些日志我可以看看?

So what is the best way this could be done? is there some kind of log I can look at?

推荐答案

监视其他应用程序的唯一方法是通过监测前台活动。这会耗尽你的电池,但没有在其他应用程序正在启动的广播,因此没有其他办法可以做到这一点。你想启动一个定时器任务,检查当前的前台活动。我会强烈建议不要这么做。 为了得到当前的前景活动使用下面的code:

The only way to monitor other apps is by monitoring foreground activity. This will drain your battery but there is no broadcast when other apps are launched and hence no other way to do it. You would like to start a timer task that checks the current foreground activity. I would highly recommend not to do it. To get current foreground activity use the following code:

ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1); 
Log.d("topActivity", "CURRENT Activity ::"
            + taskInfo.get(0).topActivity.getClassName());
ComponentName componentInfo = taskInfo.get(0).topActivity;
componentInfo.getPackageName();

您将需要以下权限:

<uses-permission android:name="android.permission.GET_TASKS"/>

这篇关于怎么办Android的显示器使用应用程序的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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