利用Android 8.0 ShortcutManager创建桌面快捷图标
生活随笔
收集整理的這篇文章主要介紹了
利用Android 8.0 ShortcutManager创建桌面快捷图标
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
創(chuàng)建方法:
/**@param context 當(dāng)前content@param targetClass 快捷圖標(biāo)打開的界面@param backClass 打開后按返回鍵返回的界面@param shortCutId shortCut 唯一id@param shortCutIcon 桌面上顯示的圖標(biāo)@param shortCutLabel 桌面圖標(biāo)下方顯示的文字*/public static void AddShortCut(Context context, Class targetClass, Class backClass, String shortCutId, int shortCutIcon, String shortCutLabel) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);if (shortcutManager != null && shortcutManager.isRequestPinShortcutSupported()) {Intent shortcutInfoIntent = new Intent(context, targetClass);shortcutInfoIntent.setAction(Intent.ACTION_VIEW); ShortcutInfo info = new ShortcutInfo.Builder(context, shortCutId).setIcon(Icon.createWithResource(context, shortCutIcon)) .setShortLabel(shortCutLabel) .setIntent(shortcutInfoIntent) .build(); PendingIntent shortcutCallbackIntent = PendingIntent.getBroadcast(context, 0, new Intent(context, backClass), PendingIntent.FLAG_UPDATE_CURRENT); shortcutManager.requestPinShortcut(info, shortcutCallbackIntent.getIntentSender());}}else{ToastUtils.show("設(shè)備不支持在桌面創(chuàng)建快捷圖標(biāo)!");}}調(diào)用:
//長(zhǎng)按創(chuàng)建桌面快捷圖標(biāo) dicBtn.setOnLongClickListener(v -> { Utils.AddShortCut(getContext(), DictionaryActivity.class, MainActivity.class, "shorcut_dictionary", R.drawable.shorcut_dictionary, getResources().getString(R.string.shorcut_dictionary));return true; });?
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的利用Android 8.0 ShortcutManager创建桌面快捷图标的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java 数字相关操作通用类 Numb
- 下一篇: Android WebView 在内部打