Android Bitmap Label Icon Size

I have problems to find out the correct launcher icon size for my shortcut.

In my Nexus 7.2, the value of android.R.dimen.app_icon_size (see code) is 96 pixels. But if I measure the actual size of the icon of other applications in the screenshot of my desktop, it is 120 pixels. After creating a shortshut, it is smaller (96 pixels) than all other application icons (120px)

On my Samsung Galaxy SII android.R.dimen.app_icon_size is 72. And that fits my screen rating.

Here is the result

DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); 

Nexus 7.2:

 android.R.dimen.app_icon_size = 96 metrics.dip = 192 metrics.density = 2.0 metrics.densityDpi = 320 metrics.heightPixels = 1824 metrics.scaledDensity = 2.0 metrics.widthPixels = 1200 metrics.xdpi = 320.842 metrics.ydpi = 322.966 

Samsung SII:

 android.R.dimen.app_icon_size = 72 metrics.dip = 108 metrics.density = 1.5 metrics.densityDpi = 240 metrics.heightPixels = 800 metrics.scaledDensity = 1.5 metrics.widthPixels = 480 metrics.xdpi = 217.71428 metrics.ydpi = 218.49463 

Here is my code:

 // Calculate launcher icon size int size = (int) getResources().getDimension(android.R.dimen.app_icon_size); int width = size; int height = size; // Create launcher icon bitmap Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); // Inflate layout to bitmap LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.shortcut, null, false); // here I edit layout, change ImageView and TextView etc... layout.setDrawingCacheEnabled(true); layout.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight()); canvas.drawBitmap(layout.getDrawingCache(), 0, 0, new Paint()); // Create SendFax intent Intent shortcutIntent = new Intent(); shortcutIntent.setClass(context, SendFax.class); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Create shortcut intent Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, description); setResult(RESULT_OK, intent); finish(); 
+2
android bitmap icons launcher shortcut
source share
3 answers

I found a working solution:

 @TargetApi(Build.VERSION_CODES.HONEYCOMB) private int launcherLargeIconSize() { ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); return activityManager.getLauncherLargeIconSize(); } int size1 = (int) getResources().getDimension(android.R.dimen.app_icon_size); int size2 = Build.VERSION.SDK_INT >= 11 ? launcherLargeIconSize() : 0; int size = size2 > size1 ? size2 : size1; 
+6
source share

If you notice that in the Android permissions folder there should be several folders available

drawable hdpi, drawable mdpi, drawable ldpi, etc. each folder has assigned images for each device, since each device displays images according to the density of the screen, some devices have a low density, and some have a high density

therefore, on one device, the size of your icon is 96 pixels, and on another 72

older and smaller devices are 48 and 36

to fix the problem, you just need to fill in the appropriate available folders using the icon file of the right size, and then you will have no problems.

For more information, read the following: Multi-screen support in android

0
source share

Getting the right launcher icon size doesn't seem as straightforward as you might expect. I know that at least tablets go one folder up in the drawables folder to display large icons expected by screen density.

This is a little more discussed.

0
source share

All Articles