[英]How to get the list of all installed shortcuts found in the homescreen Launcher in android
I wanted to get the list of all installed shortcuts in the homescreen launcher programmatically. 我想以编程方式获取主屏幕启动器中所有已安装快捷方式的列表。 I have found lots of snippets online but none of them provides the right output
我在网上找到了很多片段,但没有一个提供正确的输出
for this snippet: 对于此片段:
Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
ArrayList<Intent> intentList = new ArrayList<Intent>();
Intent intent=null;
String launchers="";
final PackageManager packageManager=getPackageManager();
for(final ResolveInfo resolveInfo:packageManager.queryIntentActivities(shortcutsIntent, 0)) {
launchers=launchers+"\n"+resolveInfo.activityInfo.packageName;
intent=packageManager
.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
intentList.add(intent);
}
this only provides the preset shortcuts like contacts, browsers,etc. 这只提供联系人,浏览器等预设快捷方式。 not exactly what is found in the homescreen.
不完全是在主屏幕上找到的。
while this snippet: 而这个片段:
PackageManager pm = getPackageManager();
Intent i = new Intent("android.intent.action.MAIN");
i.addCategory("android.intent.category.HOME");
List<ResolveInfo> lst = pm.queryIntentActivities(i, 0);
if (lst != null) {
for (ResolveInfo resolveInfo : lst) {
}
}
}
only provides the default launcher which is com.android.launcher. 仅提供com.android.launcher的默认启动器。
My answer may be late, but it might be useful for others. 我的回答可能很晚,但对其他人可能有用。
Check my code: 检查我的代码:
if (Build.VERSION.SDK_INT <8)
{
url = "content://com.android.launcher.settings/favorites?Notify=true";
}
else
{
url = "content://com.android.launcher2.settings/favorites?Notify=true";
}
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query (Uri.parse(url), null, null, null, null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.