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"/>