我想給我的用戶一個選項,以創建應用程序內特定頁面的快捷方式。 我在Whatsapp上看到類似的用法,當你長時間按下聊天,並且你能夠創建一個桌面快捷方式到這個特定的聊天。在主屏幕上創建特定活動的快捷方式
我試過找到一些關於這個functionality的文檔,但無法讓它工作。 這是我有:
活動這不是發射活動(包括意向過濾器)
<activity android:name="com.my.example.pages.Topics"
android:parentActivityName="com.my.example.pages.Apps">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
createShortcut功能
public void createShortcut(){
Intent shortcutIntent = new Intent("com.my.example.pages.Topics");
Intent.ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(getActivity(), R.drawable.app_logo);
// The result we are passing back from this activity
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Test");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
getActivity().setResult(getActivity().RESULT_OK, intent);
getActivity().finish();
Toast.makeText(getActivity(),"Shortcut created",Toast.LENGTH_SHORT).show();
}
清單
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
我可能因爲調用函數後得到Toasts,但沒有創建快捷方式,並且由於finish()方法而退出應用程序。
爲了更清晰 - 如何爲非啓動器活動創建快捷方式?
*我在其中一個viewpager片段中運行代碼。
相關:http://stackoverflow.com/questions/6988511/how-to-add-apps-shortcut-to-the-home-screen – cygery
與所有的答覆,WhatsApp應用程序非常敬重好,順利。作爲用戶,我覺得這個選項是非常有用的,甚至是必要的 – Juvi
似乎這是行得通的,「主題」必須是啓動器活動 –