APP生成桌面快捷方式

来源:互联网 发布:中医人工智能系统 编辑:程序博客网 时间:2024/05/22 17:01

在启动页oncreate()方法通过发送广播给桌面可创建快捷方式

//从sharepreference检查是否创建过boolean isInstalled = SpUtil.getBoolean(getApplicationContext(), Constacts.SHORTCUT, false);        if (!isInstalled) {            Intent intent = new Intent();            intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");            intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "应用名称");            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));//The name of the extra used to define the icon, as a Bitmap, of a shortcut.            Intent startIntent = new Intent();            startIntent.setAction("android.intent.action.MAIN");            startIntent.addCategory("android.intent.category.LAUNCHER");            startIntent.addCategory("android.intent.category.DEFAULT");            startIntent.addCategory("android.intent.category.TAB");            intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, startIntent);            sendBroadcast(intent);            //已创建,添加到sharepreference            SpUtil.putBoolean(getApplicationContext(), Constacts.SHORTCUT, true);
0 0
原创粉丝点击