5

I want to add my app Icon to created folder instead of default folder icon.

I know i can create folder with following code.

String extr = Environment.getExternalStorageDirectory().toString();
File mFolder = new File(extr + "/My Application/Downloads");
if (!mFolder.exists()) {
    mFolder.mkdirs();
}

By doing this, i'm getting following result.

enter image description here

but what i want is..

enter image description here

I have searched a lot, but no luck. can anyone help me out?

Thank you.

V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
  • 2
    As I wrote ~2 years ago, directories do not have icons. You would need to talk to the developers of the app whose screenshot you are showing, and ask them "hey, how you are deciding what icon to show?" and see what they tell you. For example, the answer could be "if the directory's name is `Snapchat`, we show the Snapchat icon". Or, "if the directory is the `getExternalFilesDir()` directory for an app, we show that app's icon". – CommonsWare Feb 15 '19 at 12:10
  • Are you sure that "Snapchat (4)" is a folder? Did you try to make a folder with name "Snapchat"? What icon appeared for created by you folder? There is a chance that file manager app changed icons for folder with some known app names. – no_fate Feb 19 '19 at 15:48

3 Answers3

8

Directories do not have icons, and so whatever app or tool your screenshot is from is adding that. You would have to ask the developers of that app or tool what algorithm they are using to determine the icon to show.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • well.. if i could contact developers of SnapChat that would be my first choice :D But thank you. +1 for Directories do not have icons. – V-rund Puro-hit Dec 15 '16 at 13:23
0

Customization of folder icon is OS dependent.

  • On Windows you will use Desktop.ini file to assign a custom icon or thumbnail image to a folder. To simplify working with Desktop.ini you can use ini4j. Basically, you will need to create Desktop.ini in the folder, that you want to customize and specify path to the icon there. (Here is similar question)
  • On Mac OS the process is different. There are ways to access icons (for example, FileView or FileSystemView, also Quaqua). However I haven't found a way to set folder icon programmatically with Java.

Note: I assumed, that you want to add icon to arbitrary folder and not your app laucher.

Oleksii Zghurskyi
  • 3,967
  • 1
  • 16
  • 17
0

After creating new directory you have to declare resource directory in your gradle file so that android studio can recognize new resource directory.

More information please refer https://developer.android.com/studio/write/add-resources

Farid Haq
  • 3,728
  • 1
  • 21
  • 15