您的位置:首页 > 其它

创建安卓桌面快捷图标

2015-08-30 17:06 281 查看
    在欢迎界面延迟几秒后调用
    SharedPreferences setting = getSharedPreferences("silent.preferences", 0);
    // 判断是否第一次启动应用程序(默认为true)
    boolean firstStart = setting.getBoolean("FIRST_START", true);
    // 第一次启动时创建桌面快捷方式
    if (firstStart) {
    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);
    // 指定快捷方式的启动对象
     shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,new Intent(this,   this.getClass()).setAction(Intent.ACTION_MAIN));
     // 快捷方式的图标
     Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
      shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
     // 发出广播
     sendBroadcast(shortcut);
     // 将第一次启动的标识设置为false
     SharedPreferences.Editor editor = setting.edit();
       editor.putBoolean("FIRST_START", false);
       // 提交设置
       editor.commit();
        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: