Android App 应该怎样创建桌面( Home Screen)图标?

2015-02-07 13:19:42 +08:00
 wangleineo
我知道可以通过广播com.android.launcher.action.INSTALL_SHORTCUT来创建App的桌面图标,但是有几个问题:
1. 有些Android系统在安装应用以后直接在Home Screen创建图标,怎样检测shortcut已经安装,以避免重复安装?
2. 在App版本升级以后,怎样更新安装过的shortcut?
3085 次点击
所在节点    问与答
1 条回复
gao117348222
2015-02-08 14:24:32 +08:00
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
//快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
shortcut.putExtra("duplicate", false); //不允许重复创建
//指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer
//注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序
// ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName());
// shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this,WXEntryActivity.class));
//快捷方式的图标
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);

避免重复安装用SharedPreferences来记录是否第一次打开。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/169018

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX