How to get the list of all installed shortcuts found in the homescreen Launcher in android

馋奶兔 提交于 2019-12-04 10:23:15

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/12738865/how-to-get-the-list-of-all-installed-shortcuts-found-in-the-homescreen-launcher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!