Java Code Examples for android.content.pm.ShortcutManager#createShortcutResultIntent()
The following examples show how to use
android.content.pm.ShortcutManager#createShortcutResultIntent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utility.java From Shelter with Do What The F*ck You Want To Public License | 5 votes |
public static void createLauncherShortcut(Context context, Intent launchIntent, Icon icon, String id, String label) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); if (shortcutManager.isRequestPinShortcutSupported()) { ShortcutInfo info = new ShortcutInfo.Builder(context, id) .setIntent(launchIntent) .setIcon(icon) .setShortLabel(label) .setLongLabel(label) .build(); Intent addIntent = shortcutManager.createShortcutResultIntent(info); shortcutManager.requestPinShortcut(info, PendingIntent.getBroadcast(context, 0, addIntent, 0).getIntentSender()); } else { // TODO: Maybe implement this for launchers without pin shortcut support? // TODO: Should be the same with the fallback for Android < O // for now just show unsupported Toast.makeText(context, context.getString(R.string.unsupported_launcher), Toast.LENGTH_LONG).show(); } } else { Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, drawableToBitmap(icon.loadDrawable(context))); context.sendBroadcast(shortcutIntent); Toast.makeText(context, R.string.shortcut_create_success, Toast.LENGTH_SHORT).show(); } }
Example 2
Source File: ShortcutService.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
@NonNull public Intent createShortcut(Contact contact, boolean legacy) { Intent intent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !legacy) { ShortcutInfo shortcut = getShortcutInfo(contact); ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class); intent = shortcutManager.createShortcutResultIntent(shortcut); } else { intent = createShortcutResultIntent(contact); } return intent; }
Example 3
Source File: ShortcutService.java From Conversations with GNU General Public License v3.0 | 5 votes |
@NonNull public Intent createShortcut(Contact contact, boolean legacy) { Intent intent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !legacy) { ShortcutInfo shortcut = getShortcutInfo(contact); ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class); intent = shortcutManager.createShortcutResultIntent(shortcut); } else { intent = createShortcutResultIntent(contact); } return intent; }
Example 4
Source File: LauncherShortcutUtils.java From FreezeYou with Apache License 2.0 | 4 votes |
static void requestCreateShortCut(String title, Intent intent, Drawable icon, String id, Context context, Bitmap bm) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { requestCreateShortCutOldApi(title, intent, icon, context, bm); } else { ShortcutManager mShortcutManager = context.getSystemService(ShortcutManager.class); if (mShortcutManager != null) { if (mShortcutManager.isRequestPinShortcutSupported()) { ShortcutInfo.Builder shortcutInfoBuilder = new ShortcutInfo.Builder(context, id); shortcutInfoBuilder.setIcon( Icon.createWithBitmap(bm == null ? getBitmapFromDrawable(icon) : bm)); shortcutInfoBuilder.setIntent(intent); shortcutInfoBuilder.setShortLabel(title); shortcutInfoBuilder.setLongLabel(title); ShortcutInfo pinShortcutInfo = shortcutInfoBuilder.build(); // Create the PendingIntent object only if your app needs to be notified // that the user allowed the shortcut to be pinned. Note that, if the // pinning operation fails, your app isn't notified. We assume here that the // app has implemented a method called createShortcutResultIntent() that // returns a broadcast intent. Intent pinnedShortcutCallbackIntent = mShortcutManager.createShortcutResultIntent(pinShortcutInfo); // Configure the intent so that your app's broadcast receiver gets // the callback successfully. PendingIntent successCallback = PendingIntent.getBroadcast(context, id.hashCode(), pinnedShortcutCallbackIntent, 0); mShortcutManager.requestPinShortcut(pinShortcutInfo, successCallback.getIntentSender()); showToast(context, R.string.requested); } else { requestCreateShortCutOldApi(title, intent, icon, context, bm); } } else { requestCreateShortCutOldApi(title, intent, icon, context, bm); } } }
Example 5
Source File: BaseNoteFragment.java From nextcloud-notes with GNU General Public License v3.0 | 4 votes |
/** * Main-Menu-Handler */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_cancel: if (originalNote == null) { db.deleteNoteAndSync(ssoAccount, note.getId()); } else { db.updateNoteAndSync(ssoAccount, localAccount, originalNote, null, null); } listener.close(); return true; case R.id.menu_delete: db.deleteNoteAndSync(ssoAccount, note.getId()); listener.close(); return true; case R.id.menu_favorite: db.toggleFavorite(ssoAccount, note, null); listener.onNoteUpdated(note); prepareFavoriteOption(item); return true; case R.id.menu_category: showCategorySelector(); return true; case R.id.menu_title: showEditTitleDialog(); return true; case R.id.menu_move: AccountPickerDialogFragment.newInstance(note.getAccountId()).show(requireActivity().getSupportFragmentManager(), BaseNoteFragment.class.getSimpleName()); return true; case R.id.menu_share: ShareUtil.openShareDialog(requireContext(), note.getTitle(), note.getContent()); return false; case MENU_ID_PIN: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ShortcutManager shortcutManager = requireActivity().getSystemService(ShortcutManager.class); if (shortcutManager != null) { if (shortcutManager.isRequestPinShortcutSupported()) { Intent intent = new Intent(getActivity(), EditNoteActivity.class); intent.putExtra(EditNoteActivity.PARAM_NOTE_ID, note.getId()); intent.setAction(ACTION_SHORTCUT); ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(getActivity(), note.getId() + "") .setShortLabel(note.getTitle()) .setIcon(Icon.createWithResource(requireActivity().getApplicationContext(), note.isFavorite() ? R.drawable.ic_star_yellow_24dp : R.drawable.ic_star_grey_ccc_24dp)) .setIntent(intent) .build(); Intent pinnedShortcutCallbackIntent = shortcutManager.createShortcutResultIntent(pinShortcutInfo); PendingIntent successCallback = PendingIntent.getBroadcast(getActivity(), /* request code */ 0, pinnedShortcutCallbackIntent, /* flags */ 0); shortcutManager.requestPinShortcut(pinShortcutInfo, successCallback.getIntentSender()); } else { Log.i(TAG, "RequestPinShortcut is not supported"); } } else { Log.e(TAG, "ShortcutManager is null"); } } return true; default: return super.onOptionsItemSelected(item); } }