Android: Get Installed Shortcuts

大城市里の小女人 提交于 2019-12-01 16:22:14

The shortcuts are private to Launcher. There is no API, and anything you try to do will be very fragile as different launcher implementations (and versions) will have different storage structures.

Here is how it is done in the Launcher...

Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
List<ResolveInfo> shortcuts = getPackageManager().queryIntentActivities(shortcutsIntent, 0);

In addition to Jonathan,

Each app can do shortcuts. Each shortcut specified in app's manifest. So you can get shortcuts list (this method in activity):
Kotlin

fun printShortcuts() {
    val shortcutIntent = Intent(Intent.ACTION_CREATE_SHORTCUT)
    val shortcuts = packageManager.queryIntentActivities(shortcutIntent, 0)
    shortcuts.forEach {
        println("name = ${it.activityInfo.name}, label = ${it.loadLabel(packageManager)}")
    }
}

It will print something like:

I/System.out: name = com.whatsapp.camera.CameraActivity, label = WhatsApp Camera
I/System.out: name = com.android.contacts.ContactShortcut, label = Contact
I/System.out: name = alias.DialShortcut, label = Direct dial
I/System.out: name = alias.MessageShortcut, label = Direct message
Sgotenks

I'm trying to do the same and there a lot of things not clear about this topic, at least not clear to me...........An example is Openapp market that create shortcuts everytime you "download" an app, but the shortcuts it is actually only a link to an html page. Anyway i have 2 android phones and in the firstone is working in the second one is not creating any shortcuts.......

in may app i do the following:

 Intent shortcutIntent = new Intent(this,FinestraPrincipaleActivity.class);
 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  shortcutIntent.putExtra("someParameter", "HelloWorld");

 Intent addIntent = new Intent();
 addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
 addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");
  addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,  
 Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));

addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
 this.sendBroadcast(addIntent);

But someone told me that the is wrong but i didn't find anyother way to create shortcuts....

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