rds*_*rds 25
主屏幕以with类别(来自javadoc )启动.使用此意图来了解将启动哪个应用程序.Intent ACTION_MAINCATEGORY_HOMEIntentResolveInfo
这将为您提供默认的Home应用程序:
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?
} else if ("android".equals(res.activityInfo.packageName)) {
// No default selected
} else {
// res.activityInfo.packageName and res.activityInfo.name gives you the default app
}
Run Code Online (Sandbox Code Playgroud)
现在,如果您想知道哪一个正在运行,则需要更多时间,因为ActivityManager很慢:
// 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
Run Code Online (Sandbox Code Playgroud)
private String findLauncherPackageName(){
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
final ResolveInfo res = getPackageManager().resolveActivity(intent, 0);
Log.e("ANDRO_ASYNC", String.format("findLauncherPackageName()%s",res.activityInfo.packageName));
return res.activityInfo.packageName;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10816 次 |
| 最近记录: |