【问题标题】:Home screen shortcut not working. application not found主屏幕快捷方式不起作用。应用程序未找到
【发布时间】:2012-04-19 21:28:00
【问题描述】:

我正在尝试在主屏幕上为我的应用程序内的活动创建快捷方式。 我设法创建了快捷方式,但是当我点击它时什么也没有发生,它说“找不到应用程序” 这是我的代码的样子:

final Intent shortcutIntent = new Intent("com.myapp.action.MyActivity");
ComponentName name = new ComponentName(getPackageName(), ".MyActivity");
shortcutIntent.setComponent(name);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "blabla..");

Parcelable iconResource =
Intent.ShortcutIconResource.fromContext(PresetsActivity.this,R.drawable.ic_application_launcher);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconResource);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");

sendBroadcast(intent);

【问题讨论】:

    标签: android launcher shortcut


    【解决方案1】:

    Intent 构造函数中没有一个将类名作为参数——您必须改为传递操作。启动活动的通常操作是 ACTION_MAIN。

    如果您想查看一些使用快捷方式和意图来做各种有趣事情的示例代码,请查看Shortcut Circus

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-22
      • 2013-06-24
      • 2018-11-22
      • 2013-06-25
      相关资源
      最近更新 更多