List of usage examples for android.content Intent EXTRA_SHORTCUT_INTENT
String EXTRA_SHORTCUT_INTENT
To view the source code for android.content Intent EXTRA_SHORTCUT_INTENT.
Click Source Link
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;/*from w w w. ja v a 2 s. c om*/ 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 ww w . j a va 2s . c o m * @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 ww w . java 2 s . c o m*/ * @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:org.onebusaway.android.util.UIUtils.java
/** * Default implementation for creating a shortcut when in shortcut mode. * * @param name The name of the shortcut. * @param destIntent The destination intent. *//*from w w w .j av a 2s .c om*/ public static final Intent makeShortcut(Context context, String name, Intent destIntent) { // Set up the container intent Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, destIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); Parcelable iconResource = Intent.ShortcutIconResource.fromContext(context, R.mipmap.ic_launcher); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); return intent; }
From source file:com.cleanwiz.applock.ui.activity.SplashActivity.java
public void createDeskShortCut() { // ????//from w w w . j a v a 2 s . com SharedPreferenceUtil.editShortCut(true); Intent shortcutIntent = new Intent(); shortcutIntent.setClass(this, SplashActivity.class); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); shortcutIntent.setAction("android.intent.action.MAIN"); shortcutIntent.addCategory("android.intent.category.LAUNCHER"); Intent resultIntent = new Intent(); resultIntent.putExtra("duplicate", false); resultIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher)); resultIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); resultIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); resultIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT"); sendBroadcast(resultIntent); resultIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); sendBroadcast(resultIntent); }
From source file:com.dnielfe.manager.AppManager.java
private void createshortcut() { Intent shortcutIntent = new Intent(AppManager.this, AppManager.class); shortcutIntent.setAction(Intent.ACTION_MAIN); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.appmanager)); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(AppManager.this, R.drawable.type_apk)); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); AppManager.this.sendBroadcast(addIntent); Toast.makeText(AppManager.this, getString(R.string.shortcutcreated), Toast.LENGTH_SHORT).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. java2s .c o m*/ 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); }
From source file:com.marlonjones.voidlauncher.InstallShortcutReceiver.java
private static PendingInstallShortcutInfo decode(String encoded, Context context) { try {/*w w w . j a va 2s.c o m*/ JSONObject object = (JSONObject) new JSONTokener(encoded).nextValue(); Intent launcherIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0); if (object.optBoolean(APP_SHORTCUT_TYPE_KEY)) { // The is an internal launcher target shortcut. UserHandleCompat user = UserManagerCompat.getInstance(context) .getUserForSerialNumber(object.getLong(USER_HANDLE_KEY)); if (user == null) { return null; } LauncherActivityInfoCompat info = LauncherAppsCompat.getInstance(context) .resolveActivity(launcherIntent, user); return info == null ? null : new PendingInstallShortcutInfo(info, context); } Intent data = new Intent(); data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent); data.putExtra(Intent.EXTRA_SHORTCUT_NAME, object.getString(NAME_KEY)); String iconBase64 = object.optString(ICON_KEY); String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY); String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY); if (iconBase64 != null && !iconBase64.isEmpty()) { byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT); Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length); data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b); } else if (iconResourceName != null && !iconResourceName.isEmpty()) { Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource(); iconResource.resourceName = iconResourceName; iconResource.packageName = iconResourcePackageName; data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); } return new PendingInstallShortcutInfo(data, context); } catch (JSONException | URISyntaxException e) { Log.d(TAG, "Exception reading shortcut to add: " + e); } return null; }
From source file:com.android.launcher3.InstallShortcutReceiver.java
private static PendingInstallShortcutInfo decode(String encoded, Context context) { try {/* ww w . ja va 2s. c om*/ JSONObject object = (JSONObject) new JSONTokener(encoded).nextValue(); Intent launcherIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0); if (object.optBoolean(APP_SHORTCUT_TYPE_KEY)) { // The is an internal launcher target shortcut. UserHandleCompat user = UserManagerCompat.getInstance(context) .getUserForSerialNumber(object.getLong(USER_HANDLE_KEY)); if (user == null) { return null; } LauncherActivityInfoCompat info = LauncherAppsCompat.getInstance(context) .resolveActivity(launcherIntent, user); return info == null ? null : new PendingInstallShortcutInfo(info, context); } Intent data = new Intent(); data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent); data.putExtra(Intent.EXTRA_SHORTCUT_NAME, object.getString(NAME_KEY)); String iconBase64 = object.optString(ICON_KEY); String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY); String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY); if (iconBase64 != null && !iconBase64.isEmpty()) { byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT); Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length); data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b); } else if (iconResourceName != null && !iconResourceName.isEmpty()) { Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource(); iconResource.resourceName = iconResourceName; iconResource.packageName = iconResourcePackageName; data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); } return new PendingInstallShortcutInfo(data, context); } catch (JSONException e) { Log.d(TAG, "Exception reading shortcut to add: " + e); } catch (URISyntaxException e) { Log.d(TAG, "Exception reading shortcut to add: " + e); } return null; }
From source file:org.zywx.wbpalmstar.engine.EUtil.java
public final void createSystemSwitcherShortCut(Context context, String shortCutName) { Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); Parcelable icon = Intent.ShortcutIconResource.fromContext(context, EResources.icon); addIntent.putExtra("duplicate", false); Intent targetIntent = new Intent(context, EBrowserActivity.class); targetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent); context.sendBroadcast(addIntent);//www . jav a2 s. co m }