9

我已经看到了制作快捷方式的方法,但我需要找到一种方法来获取手机上安装的快捷方式列表。

我希望我的用户能够选择他/她的快捷方式之一并从我的应用程序中启动它。有没有办法做到这一点(API)或者我需要一个反射方法来调用系统服务?

4

4 回答 4

5

这是它在启动器中的完成方式...

Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
List<ResolveInfo> shortcuts = getPackageManager().queryIntentActivities(shortcutsIntent, 0);
于 2012-08-12T15:18:49.963 回答
2

快捷方式是 Launcher 专用的。没有 API,您尝试做的任何事情都将非常脆弱,因为不同的启动器实现(和版本)将具有不同的存储结构。

于 2011-06-01T06:27:54.767 回答
0

除了乔纳森

每个应用程序都可以做快捷方式。应用清单中指定的每个快捷方式。所以你可以得到快捷方式列表(活动中的这个方法):
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)}")
    }
}

它将打印如下内容:

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
于 2018-02-13T11:40:04.263 回答
-2

我正在尝试做同样的事情,关于这个话题有很多不清楚的地方,至少我不清楚............一个例子是 Openapp 市场,每次你“下载”时都会创建快捷方式一个应用程序,但它的快捷方式实际上只是一个指向 html 页面的链接。无论如何,我有 2 部 android 手机,第一部正在工作,第二部没有创建任何快捷方式.......

在 May 应用程序中,我执行以下操作:

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

但是有人告诉我这是错误的,但我没有找到任何其他方法来创建快捷方式....

于 2011-06-14T14:18:23.590 回答