wangleineo
V2EX  ›  问与答

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

  •  
  •   wangleineo · Feb 7, 2015 · 3473 views
    This topic created in 4139 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
    gao117348222
        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来记录是否第一次打开。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2925 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:08 · PVG 23:08 · LAX 08:08 · JFK 11:08
    ♥ Do have faith in what you're doing.