如何让Android在主屏幕启动发现所有已安装的快捷键列表(How to get the list

2019-08-01 03:54发布

我想获得所有已安装的快捷键列表在主屏幕发射器编程。 我发现很多片段的在线,但他们没有提供正确的输出

对于这个片段:

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);    
}

这只是提供了预设快捷键如联系人,浏览器等。 不正是在主屏幕中。

而这个片段:

    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) {  
           }
       }
    }

仅提供了默认的启动是com.android.launcher。

Answer 1:

我的回答可能会迟到,但它可能是有用的人。

检查我的代码:

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);


文章来源: How to get the list of all installed shortcuts found in the homescreen Launcher in android