List of usage examples for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE
String EXTRA_SHORTCUT_ICON_RESOURCE
To view the source code for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE.
Click Source Link
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;/* 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.amaze.carbonfilemanager.fragments.MainFragment.java
private void addShortcut(LayoutElement path) { //Adding shortcut for MainActivity //on Home screen Intent shortcutIntent = new Intent(getActivity().getApplicationContext(), MainActivity.class); shortcutIntent.putExtra("path", path.getDesc()); shortcutIntent.setAction(Intent.ACTION_MAIN); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, new File(path.getDesc()).getName()); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getActivity(), R.mipmap.ic_launcher)); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); getActivity().sendBroadcast(addIntent); }
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 a2 s . c o m 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); } }