V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wangleineo
V2EX  ›  问与答

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

  •  
  •   wangleineo · 2015-02-07 13:19:42 +08:00 · 3066 次点击
    这是一个创建于 3375 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我知道可以通过广播com.android.launcher.action.INSTALL_SHORTCUT来创建App的桌面图标,但是有几个问题:
    1. 有些Android系统在安装应用以后直接在Home Screen创建图标,怎样检测shortcut已经安装,以避免重复安装?
    2. 在App版本升级以后,怎样更新安装过的shortcut?
    1 条回复    2015-02-08 14:24:32 +08:00
    gao117348222
        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来记录是否第一次打开。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2545 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:19 · PVG 16:19 · LAX 01:19 · JFK 04:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.