Search code examples
androidiconslaunchershortcut

Programmatically get launcher's icon size


I'm trying to programmatically get the launcher's icon size. It differs between devices. I don't have the assets in advance, I'm creating them.

Can I somehow query for the right icon dimensions for the specific launcher?


Solution

  • DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    switch(metrics.densityDpi){
         case DisplayMetrics.DENSITY_LOW:
                    break;
         case DisplayMetrics.DENSITY_MEDIUM:
                     break;
         case DisplayMetrics.DENSITY_HIGH:
                     break;
    }
    

    After getting the density... you will know which launcher icon is used and their Dimensions.