Actually My requirement is to get the icon color of any app installed in my device. I want to show an lock screen of that color. So how can I get the color code of any icon programmatically?
Asked
Active
Viewed 953 times
3
-
well icons have different colors inside, maybe you can try to find which color is dominant. You can also try to make list of popular application names and icon colors related to them manually. – Jemshit Apr 08 '15 at 10:31
-
at the first place, did you already consider that any icon may have (and generally does have) multiple color? – Amit K. Saha Apr 08 '15 at 10:32
-
Yes I know application icon has multiple colors inside. For example you can see in CM Security applock. In that applock it is gets the color of the app icon and shows in lock screen. – Apr 08 '15 at 10:36
2 Answers
3
if you want to get the all color's RGB value from a single icon--
Bitmap bitmap;
// create the bitmap from your obtained image
int pixel = bitmap.getPixel(x,y); // x,y is the desired position of the target pixel, for full imag, you have to do the same thing in a loop
int red = Color.red(pixel);
int green = Color.green(pixel);
int blue = Color.blue(pixel);
The int values returned are your standard 0 - 255. You can modify this code and get a color from anywhere, providing you can turn it into a bitmap. And you can use the Color API to get an actual RGB value like this:
int rgb = Color.rgb(red, blue, green); // rgb value of a single pixel,
Now, in order to get the all the pixels at once, you can use Bitmap.getPixels()
int[] allPixels = new int[bitmap.getWidth()*bitmap.getHeight()];
bitmap.getPixels(allPixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());

Amit K. Saha
- 5,871
- 2
- 27
- 35
-
Do you know how to take the color of the icon from url. For example `https://www.google.com/s2/favicons?domain=youtube.com` ? – TheCoderGuy May 29 '19 at 11:43
-
@Spritzig, the only difference would be creating the bitmap from the URL which should be a trivial. – Amit K. Saha May 29 '19 at 19:52
-
I am not getting the point can you provide a little code here in the comment. – TheCoderGuy May 29 '19 at 20:12
0
I don't know what you mean by getting the icon color, since the icon is an image, but you can fetch the icon of an known application like this: https://stackoverflow.com/a/13609127/3965178
And you can fetch all installed application like this: How to get all apps installed on android phone
Hope this will help you a bit.

Community
- 1
- 1

Lars Nielsen
- 150
- 11
-
hello Lars.....My intention is to get the color code of the installed app icon and thanks for giving me an Idea. – Apr 08 '15 at 10:45