android应用创建桌面快捷图标

来源:互联网 发布:qq飞车月光女神数据 编辑:程序博客网 时间:2024/06/11 23:40
Intent intent = new Intent();
intent.setAction( "com.android.launcher.action.INSTALL_SHORTCUT" );// 发送创建桌面快捷图标的广播
intent.putExtra(Intent. EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name ) );// 定义图标的标题
intent.putExtra( "duplicate", true); // 只能创建一个图标
intent.putExtra(Intent. EXTRA_SHORTCUT_ICON,
 BitmapFactory. decodeResource(getResources(), R.drawable.ic_launcher));// 设置图标
Intent i = new Intent( this, MainActivity. class);
intent.putExtra(Intent. EXTRA_SHORTCUT_INTENT, i);// 设置图标被点击的事件
sendBroadcast(intent); // 发送广播

//需要加入权限
 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
0 0
原创粉丝点击