安卓:我怎么知道,如果主屏幕是焦点 [英] android: how do I know if the home screen is in focus

查看:154
本文介绍了安卓:我怎么知道,如果主屏幕是焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android上运行的服务,我需要知道,如果是焦点或桌面(主屏幕)的任何应用程序处于焦点。我不知道这是否是正确的词来指代手机的主屏幕。我怎么能知道这是焦点或其他应用程序?

I have an service running on android and I need to know if is any application on focus or if the "desktop" (home screen) is in focus. I don't know if this is the proper word to refer to the home screen of the phone. How can I know if this is in focus or some other application?

服务里面我有这样的code,以获得正在运行的任务:

Inside the service I have this code to get the running tasks:

ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
// get the info from the currently running task
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;

我如何从componentInfo知道这是台式机还是没有?在模拟器中componentInfo.getPackageName()返回 com.android.launcher 但在一个星系S1(我只在这款手机上测试)返回别的东西。

How can I know from componentInfo if this is desktop or no? On emulator the componentInfo.getPackageName() returns com.android.launcher but in a galaxy s1 (I tested only in this phone) returns something else.

有任何其他方式做到这一点?

There is any other way to do this?

感谢。

推荐答案

如果你想获得控制时,主屏幕为焦点,实现一个主屏幕。

If you want to get control when "the home screen is in focus", implement a home screen.

这篇关于安卓:我怎么知道,如果主屏幕是焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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