Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 579
She Smile GM Avatar asked Oct 05 '12 02:10

She Smile GM


1 Answers

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);
like image 85
DevK Avatar answered Sep 28 '22 05:09

DevK