其中发射运行? [英] Which launcher is running?

查看:180
本文介绍了其中发射运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常有一个发射器在Android设备上。 但有时用户安装了几个,而其中只有一个是积极的。

Usually there is one launcher on an Android device. But sometimes users install a few while only one of them is active.

如何检查其发射器是我的Andr​​oid设备上当前活动的?

How can I check which launcher is currently active on my Android device?

感谢。

推荐答案

在主屏幕开始与 意图 ACTION_MAIN 与类别 CATEGORY_HOME (从的Javadoc 意图)。使用<一个href="http://developer.android.com/reference/android/content/pm/ResolveInfo.html"><$c$c>ResolveInfo这个意图知道什么应用程序将启动。

The home screen is started with the Intent ACTION_MAIN with category CATEGORY_HOME (from the javadoc for Intent). Use a ResolveInfo to this intent to know what application will start.

这会给你的默认主页的应用程序:

This will give you the default Home application:

final Intent intent = new Intent(Intent.ACTION_MAIN); 
intent.addCategory(Intent.CATEGORY_HOME); 
final ResolveInfo res = getPackageManager().resolveActivity(intent, 0); 
if (res.activityInfo == null) {
    // should not happen. A home is always installed, isn't it?
} if ("android".equals(res.activityInfo.packageName)) {
    // No default selected     
} else {
     // res.activityInfo.packageName and res.activityInfo.name gives you the default app
} 

现在,如果你想知道哪一个正在运行,这将需要更多的时间,因为 ActivityManager

Now, if you want to know which one is running, it will take more time, because ActivityManager is slow

// instead of the best, query all activities that match:
final List<ResolveInfo> list = ((PackageManager)getPackageManager()).queryIntentActivities(intent, 0);
// TODO from there, use ActivityManager to know which one is running and is in the list

这篇关于其中发射运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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