2
我对android非常陌生,我很难解决这个问题。我已经成功地在我的应用程序内创建了一个快捷方式。唯一的问题是,我不能指定点击快捷方式后会发生什么情况。它只是启动我的MainActivity,但我希望它也可以在选择主要活动时传递它的数据。以下是我有...如何在主屏幕上设置快捷方式的启动意向? Android
Intent shortcutIntent = new Intent(getActivity().getApplicationContext(),
MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, f.getName());
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getActivity().getApplicationContext(),
R.drawable.icon_folderbluegray));
addIntent.putExtra("info for Main Activity","Hello");
addIntent
.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getActivity().getApplicationContext().sendBroadcast(addIntent);
但是当我这样做,我得到空...
Bundle extras = getIntent().getExtras();
以下是我在Mainfest。
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
我应该如何实施广播接收机? – user3195590
检查我编辑答案 – Android
清单中会包含接收者标签吗? – user3195590