List of usage examples for android.content Intent EXTRA_SHORTCUT_ICON
String EXTRA_SHORTCUT_ICON
To view the source code for android.content Intent EXTRA_SHORTCUT_ICON.
Click Source Link
From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java
private void createContactShortcutIntent(Uri contactUri, String contentType, String displayName, String lookupKey, byte[] bitmapData) { Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); // Use an implicit intent without a package name set. It is reasonable for a disambiguation // dialog to appear when opening QuickContacts from the launcher. Plus, this will be more // resistant to future package name changes done to Contacts. Intent shortcutIntent = new Intent(ContactsContract.QuickContact.ACTION_QUICK_CONTACT); // When starting from the launcher, start in a new, cleared task. // CLEAR_WHEN_TASK_RESET cannot reset the root of a task, so we // clear the whole thing preemptively here since QuickContactActivity will // finish itself when launching other detail activities. We need to use // Intent.FLAG_ACTIVITY_NO_ANIMATION since not all versions of launcher will respect // the INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION intent extra. shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION); // Tell the launcher to not do its animation, because we are doing our own shortcutIntent.putExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION, true); shortcutIntent.setDataAndType(contactUri, contentType); shortcutIntent.putExtra(ContactsContract.QuickContact.EXTRA_EXCLUDE_MIMES, (String[]) null); final Bitmap icon = generateQuickContactIcon(drawable); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); if (TextUtils.isEmpty(displayName)) { intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.missing_name)); } else {// w ww . j a v a 2 s . co m intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName); } mListener.onShortcutIntentCreated(contactUri, intent); }
From source file:com.android.contacts.ShortcutIntentBuilder.java
private void createContactShortcutIntent(Uri contactUri, String contentType, String displayName, String lookupKey, byte[] bitmapData) { Intent intent = null;/*w w w.ja v a 2s .co m*/ if (TextUtils.isEmpty(displayName)) { displayName = mContext.getResources().getString(R.string.missing_name); } if (BuildCompat.isAtLeastO()) { final long contactId = ContentUris.parseId(contactUri); final ShortcutManager sm = (ShortcutManager) mContext.getSystemService(Context.SHORTCUT_SERVICE); final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); final ShortcutInfo shortcutInfo = dynamicShortcuts.getQuickContactShortcutInfo(contactId, lookupKey, displayName); if (shortcutInfo != null) { intent = sm.createShortcutResultIntent(shortcutInfo); } } final Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); final Intent shortcutIntent = ImplicitIntentsUtil.getIntentForQuickContactLauncherShortcut(mContext, contactUri); intent = intent == null ? new Intent() : intent; final Bitmap icon = generateQuickContactIcon(drawable); if (BuildCompat.isAtLeastO()) { final IconCompat compatIcon = IconCompat.createWithAdaptiveBitmap(icon); compatIcon.addToShortcutIntent(intent, null, mContext); } else { intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); } intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName); mListener.onShortcutIntentCreated(contactUri, intent); }
From source file:com.todoroo.astrid.activity.FilterListFragment.java
/** * Creates a shortcut on the user's home screen * * @param shortcutIntent/*from w w w. j a v a 2 s . c o m*/ * @param label */ private static void createShortcut(Activity activity, Filter filter, Intent shortcutIntent, String label) { if (label.length() == 0) return; Bitmap bitmap = superImposeListIcon(activity, filter.listingIcon, filter.listingTitle); Intent createShortcutIntent = new Intent(); createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label); createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); createShortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); //$NON-NLS-1$ activity.sendBroadcast(createShortcutIntent); Toast.makeText(activity, activity.getString(R.string.FLA_toast_onCreateShortcut, label), Toast.LENGTH_LONG) .show(); }
From source file:com.silentcircle.contacts.list.ShortcutIntentBuilder.java
private void createPhoneNumberShortcutIntent(Uri uri, String displayName, String lookupKey, byte[] bitmapData, String phoneNumber, int phoneType, String phoneLabel, String shortcutAction) { Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); Bitmap bitmap = null;/*from www . j a v a2 s.c om*/ Uri phoneUri = null; if (Intent.ACTION_CALL.equals(shortcutAction)) { // Make the URI a direct tel: URI so that it will always continue to work phoneUri = Uri.fromParts(Constants.SCHEME_TEL, phoneNumber, null); bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.badge_action_call); // } else { // phoneUri = Uri.fromParts(Constants.SCHEME_SMSTO, phoneNumber, null); // bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, // R.drawable.badge_action_sms); } Intent shortcutIntent = new Intent(shortcutAction, phoneUri); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName); mListener.onShortcutIntentCreated(uri, intent); }
From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java
private void createPhoneNumberShortcutIntent(Uri uri, String displayName, String lookupKey, byte[] bitmapData, String phoneNumber, int phoneType, String phoneLabel, String shortcutAction) { Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); Bitmap bitmap;/*www. jav a 2s . c o m*/ Uri phoneUri; if (Intent.ACTION_CALL.equals(shortcutAction)) { // Make the URI a direct tel: URI so that it will always continue to work phoneUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null); bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_call); } else { phoneUri = Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phoneNumber, null); bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_message_24dp); } Intent shortcutIntent = new Intent(shortcutAction, phoneUri); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); if (TextUtils.isEmpty(displayName)) { displayName = mContext.getResources().getString(R.string.missing_name); } if (TextUtils.equals(shortcutAction, Intent.ACTION_CALL)) { intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.call_by_shortcut, displayName)); } else if (TextUtils.equals(shortcutAction, Intent.ACTION_SENDTO)) { intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.sms_by_shortcut, displayName)); } mListener.onShortcutIntentCreated(uri, intent); }
From source file:com.mobileglobe.android.customdialer.common.list.ShortcutIntentBuilder.java
private void createPhoneNumberShortcutIntent(Uri uri, String displayName, String lookupKey, byte[] bitmapData, String phoneNumber, int phoneType, String phoneLabel, String shortcutAction) { Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); Bitmap bitmap;// w w w. jav a2s. c o m Uri phoneUri; if (Intent.ACTION_CALL.equals(shortcutAction)) { // Make the URI a direct tel: URI so that it will always continue to work phoneUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null); bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_call); } else { phoneUri = Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phoneNumber, null); bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_message_24dp_mirrored); } Intent shortcutIntent = new Intent(shortcutAction, phoneUri); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); if (TextUtils.isEmpty(displayName)) { displayName = mContext.getResources().getString(R.string.missing_name); } if (TextUtils.equals(shortcutAction, Intent.ACTION_CALL)) { intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.call_by_shortcut, displayName)); } else if (TextUtils.equals(shortcutAction, Intent.ACTION_SENDTO)) { intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.sms_by_shortcut, displayName)); } mListener.onShortcutIntentCreated(uri, intent); }
From source file:the.joeapollo.utils.ApolloUtils.java
/** * Used to create shortcuts for an artist, album, or playlist that is then * placed on the default launcher homescreen * //from w ww .j a v a2 s . com * @param displayName The shortcut name * @param id The ID of the artist, album, playlist, or genre * @param mimeType The MIME type of the shortcut * @param context The {@link Context} to use to */ public static void createShortcutIntent(final String displayName, final Long id, final String mimeType, final SherlockFragmentActivity context) { try { final ImageFetcher fetcher = getImageFetcher(context); Bitmap bitmap = null; if (mimeType.equals(MediaStore.Audio.Albums.CONTENT_TYPE)) { bitmap = fetcher.getCachedBitmap(displayName + Config.ALBUM_ART_SUFFIX); } else { bitmap = fetcher.getCachedBitmap(displayName); } if (bitmap == null) { bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.default_artwork); } // Intent used when the icon is touched final Intent shortcutIntent = new Intent(context, ShortcutActivity.class); shortcutIntent.setAction(Intent.ACTION_VIEW); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); shortcutIntent.putExtra(Config.ID, id); shortcutIntent.putExtra(Config.NAME, displayName); shortcutIntent.putExtra(Config.MIME_TYPE, mimeType); // Intent that actually sets the shortcut final Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapUtils.resizeAndCropCenter(bitmap, 96)); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); context.sendBroadcast(intent); Toast.makeText(context, displayName + " " + context.getString(R.string.pinned_to_home_screen), Toast.LENGTH_LONG).show(); } catch (final Exception e) { Log.e("ApolloUtils", "createShortcutIntent - " + e); Toast.makeText(context, displayName + " " + context.getString(R.string.could_not_be_pinned_to_home_screen), Toast.LENGTH_LONG).show(); } }
From source file:com.andrew.apollo.utils.ApolloUtils.java
/** * Used to create shortcuts for an artist, album, or playlist that is then * placed on the default launcher homescreen * /*from w ww . ja v a 2s . c om*/ * @param displayName The shortcut name * @param id The ID of the artist, album, playlist, or genre * @param mimeType The MIME type of the shortcut * @param context The {@link Context} to use to */ public static void createShortcutIntent(final String displayName, final Long id, final String mimeType, final SherlockFragmentActivity context) { try { final ImageFetcher fetcher = getImageFetcher(context); Bitmap bitmap = null; if (mimeType.equals(MediaStore.Audio.Albums.CONTENT_TYPE)) { bitmap = fetcher.getCachedBitmap(displayName + Config.ALBUM_ART_SUFFIX); } else { bitmap = fetcher.getCachedBitmap(displayName); } if (bitmap == null) { bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.default_artwork); } // Intent used when the icon is touched final Intent shortcutIntent = new Intent(context, ShortcutActivity.class); shortcutIntent.setAction(Intent.ACTION_VIEW); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); shortcutIntent.putExtra(Config.ID, id); shortcutIntent.putExtra(Config.NAME, displayName); shortcutIntent.putExtra(Config.MIME_TYPE, mimeType); // Intent that actually sets the shortcut final Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapUtils.resizeAndCropCenter(bitmap, 96)); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); context.sendBroadcast(intent); Crouton.makeText(context, displayName + " " + context.getString(R.string.pinned_to_home_screen), Crouton.STYLE_CONFIRM).show(); } catch (final Exception e) { Log.e("ApolloUtils", "createShortcutIntent - " + e); Crouton.makeText(context, displayName + " " + context.getString(R.string.could_not_be_pinned_to_home_screen), Crouton.STYLE_ALERT).show(); } }
From source file:com.android.contacts.ShortcutIntentBuilder.java
private void createPhoneNumberShortcutIntent(Uri uri, String displayName, String lookupKey, byte[] bitmapData, String phoneNumber, int phoneType, String phoneLabel, String shortcutAction) { final Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey); final Bitmap icon; final Uri phoneUri; final String shortcutName; if (TextUtils.isEmpty(displayName)) { displayName = mContext.getResources().getString(R.string.missing_name); }// w w w .ja v a 2 s.com if (Intent.ACTION_CALL.equals(shortcutAction)) { // Make the URI a direct tel: URI so that it will always continue to work phoneUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null); icon = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.quantum_ic_phone_vd_theme_24); shortcutName = mContext.getResources().getString(R.string.call_by_shortcut, displayName); } else { phoneUri = Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phoneNumber, null); icon = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.quantum_ic_message_vd_theme_24); shortcutName = mContext.getResources().getString(R.string.sms_by_shortcut, displayName); } final Intent shortcutIntent = new Intent(shortcutAction, phoneUri); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent intent = null; IconCompat compatAdaptiveIcon = null; if (BuildCompat.isAtLeastO()) { compatAdaptiveIcon = IconCompat.createWithAdaptiveBitmap(icon); final ShortcutManager sm = (ShortcutManager) mContext.getSystemService(Context.SHORTCUT_SERVICE); final String id = shortcutAction + lookupKey + phoneUri.toString().hashCode(); final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext); final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo(id, displayName, shortcutIntent, compatAdaptiveIcon.toIcon()); if (shortcutInfo != null) { intent = sm.createShortcutResultIntent(shortcutInfo); } } intent = intent == null ? new Intent() : intent; // This will be non-null in O and above. if (compatAdaptiveIcon != null) { compatAdaptiveIcon.addToShortcutIntent(intent, null, mContext); } else { intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); } intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName); mListener.onShortcutIntentCreated(uri, intent); }