【发布时间】:2018-05-25 23:34:20
【问题描述】:
我们为我们的两个应用屏幕启用了快捷方式。使用 manifest,我们已经初始化了 Activity,它指的是下面的快捷方式。
<activity
android:name=".ui.shortcuts.ShortCut1"
android:screenOrientation="portrait"
android:icon="@drawable/shortcut1"
android:label="@string/app_shortcut_name1"
android:theme="@style/AppLightTheme">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.CREATE_SHORTCUT" />
</intent-filter>
</activity>
从代码中,我启用了如下快捷方式。
Intent shortcutIntent = null;
shortcutIntent = new Intent(ApplicationNekt.getContext(), ShortCut1.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra("duplicate", false);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, ApplicationNekt.getContext().getString(R.string.app_shortcut_name1));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(ApplicationNekt.getContext(), R.drawable.shortcut1));
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
ApplicationNekt.getContext().sendBroadcast(intent);
现在在 Nova 和 Action 启动器中,它们会在快捷方式部分下显示快捷方式,其中包含我在清单中提供的图标和文本。如果我单击并按住 ,我可以将图标放在主页选项卡上。在那之后,我的目标活动立即打开。但是当我回到手机主屏幕时,他们在上一步中创建的快捷方式图标被删除了。
我错过了什么吗?
【问题讨论】:
标签: android shortcut launcher android-launcher