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.marlonjones.voidlauncher.InstallShortcutReceiver.java
private static PendingInstallShortcutInfo decode(String encoded, Context context) { try {// w ww . j av a2s . 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 {/*from w ww . j a v a 2 s. 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:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Allows to install a new icon for the application. * * This method need two additional permissions in the application: * * <code>//from w w w . j a v a 2 s .c om * <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> * </code> * * @param context The application context. * @param appMain The application main class * @param appName The application name * @param appIcon The bitmap of the application icon. Can be null. If null, the * appIconResId must be provided. * @param appIconResId Specify this only if no bitmap is set in the call to this method. */ public static void application_shortcutAdd(Context context, Class appMain, String appName, Bitmap appIcon, int appIconResId, boolean removeCurrent) { // Intent launcher of the application Intent shortcutIntent = new Intent("android.intent.action.MAIN"); shortcutIntent.addCategory("android.intent.category.LAUNCHER"); shortcutIntent.setClass(context, appMain); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //Intent to add the new application icon. // // Decorate the shortcut Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName); if (appIcon != null) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, appIcon); } else if (appIconResId != 0) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context.getApplicationContext(), appIconResId)); } // Inform launcher to create shortcut addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); context.sendBroadcast(addIntent); }
From source file:com.xabber.android.ui.activity.ContactList.java
private void createShortcut(AbstractContact abstractContact) { Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, ChatViewer.createShortCutIntent(this, abstractContact.getAccount(), abstractContact.getUser())); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, abstractContact.getName()); Bitmap bitmap;/* w w w . j a v a 2s. com*/ if (MUCManager.getInstance().hasRoom(abstractContact.getAccount(), abstractContact.getUser())) { bitmap = AvatarManager.getInstance().getRoomBitmap(abstractContact.getUser()); } else { bitmap = AvatarManager.getInstance().getUserBitmap(abstractContact.getUser()); } intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, AvatarManager.getInstance().createShortcutBitmap(bitmap)); setResult(RESULT_OK, intent); }
From source file:org.mozilla.gecko.GeckoAppShell.java
public static void createShortcut(final String aTitle, final String aURI, final Bitmap aIcon, final String aType) { getHandler().post(new Runnable() { public void run() { Log.w(LOGTAG, "createShortcut for " + aURI + " [" + aTitle + "] > " + aType); // the intent to be launched by the shortcut Intent shortcutIntent = new Intent(); if (aType.equalsIgnoreCase("webapp")) { shortcutIntent.setAction(GeckoApp.ACTION_WEBAPP); shortcutIntent.setData(Uri.parse(aURI)); } else { shortcutIntent.setAction(GeckoApp.ACTION_BOOKMARK); shortcutIntent.setData(Uri.parse(aURI)); }//from w ww. j ava 2 s . c o m shortcutIntent.setClassName(GeckoApp.mAppContext, GeckoApp.mAppContext.getPackageName() + ".App"); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); if (aTitle != null) intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, aTitle); else intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, aURI); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, getLauncherIcon(aIcon)); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); GeckoApp.mAppContext.sendBroadcast(intent); } }); }
From source file:com.xabber.android.ui.activity.ContactListActivity.java
private void createShortcut(AbstractContact abstractContact) { Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, ChatActivity.createClearTopIntent(this, abstractContact.getAccount(), abstractContact.getUser())); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, abstractContact.getName()); Bitmap bitmap;/*from ww w. j ava 2s . co m*/ if (MUCManager.getInstance().hasRoom(abstractContact.getAccount(), abstractContact.getUser())) { bitmap = AvatarManager.getInstance().getRoomBitmap(abstractContact.getUser()); } else { bitmap = AvatarManager.getInstance().getUserBitmap(abstractContact.getUser()); } intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, AvatarManager.getInstance().createShortcutBitmap(bitmap)); setResult(RESULT_OK, intent); }
From source file:kr.wdream.storyshop.AndroidUtilities.java
private static Intent createShortcutIntent(long did, boolean forDelete) { Intent shortcutIntent = new Intent(ApplicationLoader.applicationContext, OpenChatReceiver.class); int lower_id = (int) did; int high_id = (int) (did >> 32); TLRPC.User user = null;/*ww w . ja va 2 s . c o m*/ TLRPC.Chat chat = null; if (lower_id == 0) { shortcutIntent.putExtra("encId", high_id); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id); if (encryptedChat == null) { return null; } user = MessagesController.getInstance().getUser(encryptedChat.user_id); } else if (lower_id > 0) { shortcutIntent.putExtra("userId", lower_id); user = MessagesController.getInstance().getUser(lower_id); } else if (lower_id < 0) { chat = MessagesController.getInstance().getChat(-lower_id); shortcutIntent.putExtra("chatId", -lower_id); } else { return null; } if (user == null && chat == null) { return null; } String name; TLRPC.FileLocation photo = null; if (user != null) { name = ContactsController.formatName(user.first_name, user.last_name); if (user.photo != null) { photo = user.photo.photo_small; } } else { name = chat.title; if (chat.photo != null) { photo = chat.photo.photo_small; } } shortcutIntent.setAction("com.tmessages.openchat" + did); shortcutIntent.addFlags(0x4000000); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); addIntent.putExtra("duplicate", false); if (!forDelete) { Bitmap bitmap = null; if (photo != null) { try { File path = FileLoader.getPathToAttach(photo, true); bitmap = BitmapFactory.decodeFile(path.toString()); if (bitmap != null) { int size = AndroidUtilities.dp(58); Bitmap result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); result.eraseColor(Color.TRANSPARENT); Canvas canvas = new Canvas(result); BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); if (roundPaint == null) { roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); bitmapRect = new RectF(); } float scale = size / (float) bitmap.getWidth(); canvas.save(); canvas.scale(scale, scale); roundPaint.setShader(shader); bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint); canvas.restore(); Drawable drawable = ApplicationLoader.applicationContext.getResources() .getDrawable(R.drawable.book_logo); int w = AndroidUtilities.dp(15); int left = size - w - AndroidUtilities.dp(2); int top = size - w - AndroidUtilities.dp(2); drawable.setBounds(left, top, left + w, top + w); drawable.draw(canvas); try { canvas.setBitmap(null); } catch (Exception e) { //don't promt, this will crash on 2.x } bitmap = result; } } catch (Throwable e) { FileLog.e("tmessages", e); } } if (bitmap != null) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); } else { if (user != null) { if (user.bot) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_bot)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_user)); } } else if (chat != null) { if (ChatObject.isChannel(chat) && !chat.megagroup) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_channel)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_group)); } } } } return addIntent; }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
private static Intent createShortcutIntent(long did, boolean forDelete) { Intent shortcutIntent = new Intent(ApplicationLoader.applicationContext, OpenChatReceiver.class); int lower_id = (int) did; int high_id = (int) (did >> 32); TLRPC.User user = null;/* w w w . j a v a 2 s .com*/ TLRPC.Chat chat = null; if (lower_id == 0) { shortcutIntent.putExtra("encId", high_id); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id); if (encryptedChat == null) { return null; } user = MessagesController.getInstance().getUser(encryptedChat.user_id); } else if (lower_id > 0) { shortcutIntent.putExtra("userId", lower_id); user = MessagesController.getInstance().getUser(lower_id); } else if (lower_id < 0) { chat = MessagesController.getInstance().getChat(-lower_id); shortcutIntent.putExtra("chatId", -lower_id); } else { return null; } if (user == null && chat == null) { return null; } String name; TLRPC.FileLocation photo = null; if (user != null) { name = ContactsController.formatName(user.first_name, user.last_name); if (user.photo != null) { photo = user.photo.photo_small; } } else { name = chat.title; if (chat.photo != null) { photo = chat.photo.photo_small; } } shortcutIntent.setAction("com.tmessages.openchat" + did); shortcutIntent.addFlags(0x4000000); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); addIntent.putExtra("duplicate", false); if (!forDelete) { Bitmap bitmap = null; if (photo != null) { try { File path = FileLoader.getPathToAttach(photo, true); bitmap = BitmapFactory.decodeFile(path.toString()); if (bitmap != null) { int size = AndroidUtilities.dp(58); Bitmap result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); result.eraseColor(Color.TRANSPARENT); Canvas canvas = new Canvas(result); BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); if (roundPaint == null) { roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); bitmapRect = new RectF(); } float scale = size / (float) bitmap.getWidth(); canvas.save(); canvas.scale(scale, scale); roundPaint.setShader(shader); bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint); canvas.restore(); Drawable drawable = ApplicationLoader.applicationContext.getResources() .getDrawable(R.drawable.book_logo); int w = AndroidUtilities.dp(15); int left = size - w - AndroidUtilities.dp(2); int top = size - w - AndroidUtilities.dp(2); drawable.setBounds(left, top, left + w, top + w); drawable.draw(canvas); try { canvas.setBitmap(null); } catch (Exception e) { //don't promt, this will crash on 2.x } bitmap = result; } } catch (Throwable e) { FileLog.e(e); } } if (bitmap != null) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); } else { if (user != null) { if (user.bot) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_bot)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_user)); } } else if (chat != null) { if (ChatObject.isChannel(chat) && !chat.megagroup) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_channel)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_group)); } } } } return addIntent; }
From source file:com.cognizant.trumobi.PersonaLauncher.java
private static PersonaApplicationInfo infoFromShortcutIntent(Context context, Intent data) { Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); Drawable icon = null;//from w w w .j av a2s . c om boolean filtered = false; boolean customIcon = false; ShortcutIconResource iconResource = null; if (bitmap != null) { icon = new PersonaFastBitmapDrawable(PersonaUtilities.createBitmapThumbnail(bitmap, context)); filtered = true; customIcon = true; } else { Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); if (extra != null && extra instanceof ShortcutIconResource) { try { iconResource = (ShortcutIconResource) extra; final PackageManager packageManager = context.getPackageManager(); Resources resources = packageManager.getResourcesForApplication(iconResource.packageName); final int id = resources.getIdentifier(iconResource.resourceName, null, null); icon = resources.getDrawable(id); } catch (Exception e) { PersonaLog.w(LOG_TAG, "Could not load shortcut icon: " + extra); } } } if (icon == null) { icon = context.getPackageManager().getDefaultActivityIcon(); } final PersonaApplicationInfo info = new PersonaApplicationInfo(); info.icon = icon; info.filtered = filtered; info.title = name; info.intent = intent; info.customIcon = customIcon; info.iconResource = iconResource; return info; }
From source file:com.cognizant.trumobi.PersonaLauncher.java
private void completeEditShirtcut(Intent data) { if (!data.hasExtra(PersonaCustomShirtcutActivity.EXTRA_APPLICATIONINFO)) return;//from w w w .ja v a2s. com long appInfoId = data.getLongExtra(PersonaCustomShirtcutActivity.EXTRA_APPLICATIONINFO, 0); PersonaApplicationInfo info = PersonaLauncherModel.loadApplicationInfoById(this, appInfoId); if (info != null) { Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); Drawable icon = null; boolean customIcon = false; ShortcutIconResource iconResource = null; if (bitmap != null) { icon = new PersonaFastBitmapDrawable(PersonaUtilities.createBitmapThumbnail(bitmap, this)); customIcon = true; } else { Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); if (extra != null && extra instanceof ShortcutIconResource) { try { iconResource = (ShortcutIconResource) extra; final PackageManager packageManager = getPackageManager(); Resources resources = packageManager.getResourcesForApplication(iconResource.packageName); final int id = resources.getIdentifier(iconResource.resourceName, null, null); icon = resources.getDrawable(id); } catch (Exception e) { PersonaLog.w(LOG_TAG, "Could not load shortcut icon: " + extra); } } } if (icon != null) { info.icon = icon; info.customIcon = customIcon; info.iconResource = iconResource; } info.itemType = PersonaLauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; info.title = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); info.intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); PersonaLauncherModel.updateItemInDatabase(this, info); if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_MAB) mHandleView.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_LAB) mLAB.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_LAB2) mLAB2.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_RAB) mRAB.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_RAB2) mRAB2.UpdateLaunchInfo(info); mWorkspace.updateShortcutFromApplicationInfo(info); } }