其中发射运行?

由网友(蕶誶の汜忆)分享简介:通常有一个发射器在Android设备上。但有时用户安装了几个,而其中只有一个是积极的。Usually there is one launcher on an Android device.But sometimes users install a few while only one of them is act...

通常有一个发射器在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 意图)。使用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
阅读全文

相关推荐

最新文章