Created
August 20, 2014 16:33
-
-
Save julianshen/0c85f482caac64ed26b7 to your computer and use it in GitHub Desktop.
shortcut example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); | |
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "test"); | |
PackageManager pm = getPackageManager(); | |
ApplicationInfo youtube = null; | |
ApplicationInfo plus = null; | |
ApplicationInfo map = null; | |
try { | |
youtube = pm.getApplicationInfo("com.google.android.youtube", PackageScanIntentService.FLAGS_PACKAGE); | |
plus = pm.getApplicationInfo("com.google.android.apps.plus", PackageScanIntentService.FLAGS_PACKAGE); | |
map = pm.getApplicationInfo("com.google.android.apps.maps", PackageScanIntentService.FLAGS_PACKAGE); | |
BitmapFactory.Options options = new BitmapFactory.Options(); | |
options.inSampleSize = 2; | |
Bitmap youtubeIcon = BitmapFactory.decodeResource(pm.getResourcesForApplication(youtube), youtube.icon, options); | |
Bitmap plusIcon = BitmapFactory.decodeResource(pm.getResourcesForApplication(plus), plus.icon, options); | |
Bitmap mapIcon = BitmapFactory.decodeResource(pm.getResourcesForApplication(map), map.icon, options); | |
Bitmap icon = Bitmap.createBitmap(youtubeIcon.getWidth() * 2, youtubeIcon.getHeight() * 2, Bitmap.Config.ARGB_8888); | |
Canvas c = new Canvas(icon); | |
c.drawBitmap(youtubeIcon, 0, 0, null); | |
c.drawBitmap(plusIcon, plusIcon.getWidth(), 0, null); | |
c.drawBitmap(mapIcon, 0, mapIcon.getHeight(), null); | |
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); | |
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent); | |
intent.putExtra("duplicate", false); | |
sendBroadcast(intent); | |
} catch (PackageManager.NameNotFoundException e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment