1、添加權(quán)限(必須)
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "hello");//快捷鍵名字可以任意,不過最好為app名稱
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(activity, R.drawable.ic_launcher);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
intent.putExtra("duplicate", false);//不允許重復(fù)創(chuàng)建
activity.sendBroadcast(intent);//發(fā)送廣播創(chuàng)建快捷鍵
}
3、快捷鍵也可以指向非Launcher activity,只需要在AndroidManifest中對應(yīng)的Activity 中添加如下配置
新聞熱點
疑難解答
圖片精選