I do not actually know what this is called. But I have seen app icons beside their directories in internal storage. I assume that it's some kind of association. I would like to know how to achieve this for a directory made by my app.
Here is a screenshot showing Telegram and WhatsApp doing what I want:
I am using the following to create a directory:
File(Environment.getExternalStorageDirectory(), "MyApp").mkdirs()
What else should I add to the above code?
What else should I add to the above code?
Nothing. And note that this code does not work on Android 10 (by default) or Android R+ (for all apps), as external storage has been locked down.
But I have seen app icons beside their directories in internal storage.
Note that from an Android SDK standpoint, you are looking at external storage. More importantly, you are looking at external storage through some app.
I would like to know how to achieve this for a directory made by my app.
There is nothing in Android directly for this. You will need to talk to the developers of the app that you used (where you see this icon) and ask what they are doing. It could be as simple as "see if there is an installed app with the same name as the directory" or "see if there is an installed launcher icon with the same name as the directory".
Because I have seen it all file managers I have used
That means that you have more people that you can contact to see what they are doing. Again, there is nothing in the OS for this. After all, if there were, I could write an app to associate my app icon with every directory, and others could do the same. Whatever these file managers are doing, hopefully it is based on information that apps cannot manipulate to somehow spam the association information.
I'm currently trying to figure out how to set a custom image for a external storage directory I'm creating some time in the app. If you're probably using a file browser like ES File Explorer you will see that some apps like WhatsApp but also smaller projects have an extra little picture or app logo added to their folder.
Is this possible to set by code?
You can't set one that other apps use. There's no such concept as an image for a directory. Inside your own app you can do whatever you want, you have to write any file explorer yourself.
I don't have any programming knowledge, but I have installed Eclipse, and android SDK. I want to package some wallpapers into an apk and publish them in the android market. Can someone show me a tutorial or explain how to do it?
Thanks
Files placed in your res folder when you build your application are placed inside the apk.
Though they will not be avaliable for external use other than your own application. Aka, you will not be able select them via the built in wallpaper picker options.
You would have to have the apk copy the resource files to the SDCard when it is run.
Actually here is another question asking the same thing:
How to put a wallpaper inside an apk file?
Its relatively straight forward but requires some basic android and programming skills.
Store all your wallpapers in your res folder (apk).
WHen the application launches, one by one, save the resource file to the SDCard. (Check if they already exist first).
The user can now navigate his/her photos and see your wallpapers. - And hence able to set them as wallpapers.
If you don't have any programming knowledge, it doesn't matter. Here is an android wallpaper app example code, you can easily replace your image url (which should be on internet) inside.
Android Wallpaper App Tutorial (1-4)
I have images, which are read from sdcard only by particular application so I want to hide it from image gallery. I have put .nomedia file in it, but this file is ignored, images are still showing in Gallery. I have put it with "." in the beginning. Still not working. Any ideas?
I'm guessing you're using Android 4.0, as .nomedia functioned properly until then. The AOSP bug report for the issue explains:
MediaScanner on Android 4.0 fails to forget already-indexed files when it encounters a .nomedia file, but it does honor it if it's present on the first pass. So the workaround is to simply rename the directory. Of course you can change the name back after the next scan, if you like.
Update: I suppose the complete solution would be to actually force a media scan after renaming the directory. I haven't tried it, but something like this should do the trick:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" +
Environment.getExternalStorageDirectory())));
Well... I admit I'm only guessing, but since it got a +1 in the comment, I'll give it a whirl as an answer. Since this is your own app, change the image file's extension to something totally unique ".myimagefile" for instance, and see if that hides it from Android. Meanwhile you know what files to load into your own app, and how to save them.
The .nomedia bug is right and you CAN add it to a preexisting image folder.
You can force the gallery to re-index after you created the .nomedia file by renaming the folder, run gallery (the "hidden folder should now be missing), and rename the folder back to what you want. It should remain hidden.
I just did it again to ensure it works on my phone. Android 4.0.4.
Here's something I found myself:
http://www.transformerforums.com/forum/asus-transformer-faq/17765-solved-nomedia-doesnt-work-under-honeycomb-ics.html
However, a little alteration to that method:
Download and install SDRescan app
Clear data for Gallery app
Clear data for Media Storage app
Open SDRescan app downloaded from step 1
SDCard should be re-scanned and all directories containing .nomedia files should be ignored at this point.
In my memory card I have thousands of photos that overwhelm the media-scanner. Then in the root folder on my memory card, renamed from "RootFolder" to ".RootFolder"
Became the hidden directory and not use more .nomedia
Try this.
The .nomedia file is preventive, not curative (in Android 4.0), and it is a bug.
If you had a .nomedia file and images are already in it, Gallery will still search for images.
You need to create your .nomedia file before puting images in it.
Edit: all folders starting with a dot are not scanned (because hidden).
With Media Storage 4.1.1 on my Samsung Galaxy Note 2, none of the tricks given above works fully, in this sense: directories containing .nomedia files are still scanned, which can drain the battery a lot (though the result is ignored in the gallery), and also directories with names starting with a '.' are still scanned :-(
I resorted to using the "Media Scanner Root" app, which allows to disable the crappy media scanner altogether. This is apparently achieved by something like pm disable com.android.providers.media/com.android.providers.media.MediaScannerReceiver
BTW, disabling/freezing the Media Storage app itself has the bad effect that the selection and binding of ringtones and notifications does not work any more (what a wonderful design), but when only disabling its scanner component, one can still use, e.g., the ES File Explorer for selecting tones.
Gallery is not updated so often and some thumbnails are still on the view. For this u need to reboot the phone or programmatically update gallery, by following code.
/**
* This method is must to reflect changes on gallery, if some file is
* deleted or moved, <b> no updation is shown on gallery till phone is
* rebooted </b> or <i>till this method UpdateGallery(Activity activity) is
* called</i> UpdateGallery
*/
public static void UpdateGallery(Activity activity) {
activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri
.parse("file://" + Environment.getExternalStorageDirectory())));
}
You might consider using the APK Expansion Zip Library (requires API level 5 or above) to read files that you will have installed to the SD card as part of a Zip archive. A description of this library can be found here:
http://developer.android.com/guide/market/expansion-files.html#ZipLib
Presumably, files stored in a ZIP archive on your SD card will not be displayed by the Gallery.
In addition, if you have images that your app reads from (but does not write to) the SD card, and that should only be available to your own app, and that could be delivered when your app is installed or updated, then it might make sense to take advantage of a new Google Play facility to incorporate them as part of your app when it is installed.
I'm guessing that you are storing your images to the SD card because they are too large to fit into your APK file (given its 50MB size limit, which is even smaller than that in practice for certain devices, due to buffering issues).
If so, then you might consider that Google Play, as of 3/5/2012, supports the attachment (to your app) of up to two "expansion files" of up to 2 Gigabytes each. The APK still has a 50MB maximum, but the expansion files raise the total storage available to over 4 GB. Those expansion files are served for you by Google, and they are maintained in a specific SD card folder that is specific to your app, and can be accessed using an API provided by the Downloader Library (requires API level 5 or above).
Here is Google's announcement of this change:
http://android-developers.blogspot.in/2012/03/android-apps-break-50mb-barrier.html
And here is a detailed description of the facility:
http://developer.android.com/guide/market/expansion-files.html
Note that while this facility is new, the libraries have been supplied with the Android SDK for use with earlier API levels. For example, on my installation, I find the API-8 versions here:
<Android SDK base folder>\extras\google\play_apk_expansion\
That same folder includes the abovementioned APK expansion Zip library in its zip_file sub-folder.
I have not personally used this facility yet myself, and so am describing this based solely on the cited references.
I'm wanting to include some wallpapers and custom icons with my next application update. What's the best way to go about that in Android? I've been doing some searching but I haven't seen anything satisfactory.
Thanks.
Just change the icon and the background and update the app. Or do you mean something else?
I know if your app moves/copies the files to the user's SD card then the media scanner should pick it up and include in the Gallery app. Which can then be used as a wallpaper. But as for using them directly from your app, I'm not sure.
Might be good to not include them in the app directly, but allow the user to choose to download them from within your app (if you have a server or external site you can host them on). That would keep the size of your app small, and allow you to download them directly to the user's SD card.