AI摘要
文章介绍了如何在Android系统中创建程序快捷方式,但不直接添加到桌面,而是添加到添加快捷方式窗口中。通过代码示例,展示了如何设置快捷方式的名称、图标和执行的Intent,最后通过setResult方法将快捷方式添加到窗口。
文章介绍了如何
voidsetshortCut() {
Intent addShortcut=newIntent();
//设置快捷方式的名字
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,"快捷方式练习");
//构建快捷方式中专门的图标
Parcelable icon=Intent.ShortcutIconResource.fromContext(
ShortcutTest.this, R.drawable.icon);
//添加快捷方式图标
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
//构建快捷方式执行的Intent
Intent mailto=newIntent(this, ShortcutTest.class);
//添加快捷方式Intent
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mailto);
//正常
setResult(RESULT_OK, addShortcut);
}