转载:http://blog.youkuaiyun.com/luck_apple/article/details/7173104
首先需要权限:
- <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
- Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
- ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon); //图标
- intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
- intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name)); //名称
- intent.putExtra("duplicate", false);
- Intent sIntent = new Intent(Intent.ACTION_MAIN);
- sIntent.addCategory(Intent.CATEGORY_LAUNCHER);
- sIntent.setClass(this, MainActivity.class);
- intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, sIntent);
- sendBroadcast(intent);
本文介绍如何在Android应用中为用户的主屏幕创建一个自定义的快捷方式。通过使用特定的权限和Intent,开发者可以轻松地实现这一功能,提高应用的易用性和用户参与度。
2362

被折叠的 条评论
为什么被折叠?



