This topic created in 4117 days ago, the information mentioned may be changed or developed.
我知道可以通过广播com.android.launcher.action.INSTALL_SHORTCUT来创建App的桌面图标,但是有几个问题:
1. 有些Android系统在安装应用以后直接在Home Screen创建图标,怎样检测shortcut已经安装,以避免重复安装?
2. 在App版本升级以后,怎样更新安装过的shortcut?
1 replies • 2015-02-08 14:24:32 +08:00
 |
|
1
gao117348222 Feb 8, 2015
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来记录是否第一次打开。
|