添加快捷方式
 private void addShortcut(String name) {        // 设置关联程序        Intent launcherIntent = new Intent(this, SplashActivity.class);        launcherIntent.setAction(Intent.ACTION_MAIN);        launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);        Intent addShortcutIntent = new Intent();        addShortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");        // 不允许重复创建        addShortcutIntent.putExtra("duplicate", false);        // 名字        addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);        // 图标        addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,                Intent.ShortcutIconResource.fromContext(SplashActivity.this,                        R.drawable.icon));        addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent);        // 发送广播        sendBroadcast(addShortcutIntent);    }


不要忘了在manifest中添加权限哦
<!-- 添加快捷方式 -->    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />    <!-- 移除快捷方式 -->    <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />    <!-- 查询快捷方式 -->    <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />


这样程序在第一次运行的时候会自动创建快捷方式,以后每次启动的时候会提示已创建快捷方式,这样会觉得很烦,所以我在程序中做了下面的操作:
 SharedPreferences sharedPraferences = getSharedPreferences("com.rosevision.ofashion", Context.MODE_PRIVATE);        if (sharedPraferences.getInt("addShortcut", 0) == 0) {            addShortcut(getResources().getString(R.string.app_name));            sharedPraferences.edit().putInt("addShortcut",1).apply();        }

这样处理以后,程序只有在每一次运行的时候自动创建快捷方式,以后每次启动的时候会判断是否已经创建了快捷方式,如果没有的话再去创建

更多相关文章

  1. Android应用程序键盘(Keyboard)消息处理机制分析(23)
  2. Android判断程序是否第一次启动
  3. Android 返回键双击退出程序
  4. 状态栏去掉机主图标
  5. Android应用程序窗口(Activity)的测量(Measure)、布局(Layout)和绘制(Dr
  6. Android应用程序窗口(Activity)的测量(Measure)、布局(Layout)和绘制(Dr
  7. Android应用程序组成部分
  8. adb shell 命令查看android 应用程序 创建的 sqlite 数据库
  9. 在Android程序中使用MQTT

随机推荐

  1. Android(安卓)Studio 编译系统源码
  2. logcat使用方法
  3. android6.0以后删除HttpClient的解决方法
  4. Custom View
  5. ViewPager实现引导页
  6. 安卓设备修改屏幕像素密度以及查看屏幕分
  7. 【odroid-xu3】 ODROID-XU3软件环境搭建
  8. Android常用组件整理
  9. 类似home的弹出菜单(SlidingDrawer)
  10. RK3288 Android(安卓)5.x USB存在的BUG引