App Structure

This is the folder structure of the Android Telegram app.

App Cache for Cloud Chats
/storage
|-- sdcard0 or sdcard1 (depends on phone)
|   -- Telegram
|       -- Telegram Images
|       -- Telegram Documents
|       -- Telegram Audio
|       -- Telegram Video
Android Cache for App
/storage
|-- sdcard
|   -- android
|       -- data
|           -- org.telegram.messenger
|               -- cache

The cache folder is the Android cache folder for Telegram.

Manually Saved Images
/storage
|-- sdcard
|   -- Pictures
|       -- Telegram

This path is used when the user opens an image » taps on "…" » Save to Gallery. A copy of the image is saved into this folder.


Cache Explanation

In /android/data/org.telegram.messenger/cache (aka the Android Cache) we keep small avatars, media / document previews, temporary files, and Secret Chat media / documents.

The app moves files (images, videos, voice messages, and 'files') which were received in Cloud Chats to Telegram/<Telegram sub folders>.

Why is it this way?
The main reason for having Telegram Images, Videos, etc. folders is because users would like to save all incoming images to the gallery.

Why not in the /android/data/org.telegram.messenger/cache folder?
If media scan intent runs, there will be an album called Cache.

Why no sub folder in /android/data/org.telegram.messenger/cache?
If users clear the cache, they will get many non-working images in the gallery.

After moving the files - which is done automatically - it's no longer the "official Android cache", so it's not cleared via Android Settings » Apps » Telegram » Clear Cache. If the user deletes the cache (Android Settings » Apps » Telegram » Clear Cache), cached profile images and even files from Secret Chats are deleted. In the Secret Chat, the user has to manually download each file again from the Telegram Cloud.

Save to Gallery in Telegram Settings

The Telegram app runs media scan intent so the system knows what to do with the files. In other words, Android takes care of the files in its own database. So it knows when an image is or is not allowed to be displayed in the gallery.

Example:

  1. User receives the images yes.jpg, no.jpg, and yes2.jpg.
  2. User selects Save to Gallery for yes.jpg and yes2.jpg.

In the Gallery, the user will see yes.jpg and yes2.jpg. The gallery will not display no.jpg.


File names

file name = "datacenterId_localId.extension"

File names cannot be changed at the moment. If the file names are changed and the user relogs, Telegram would have to re-download all the files, since it would not know which name belongs to which file.

Deleting Cache

Cloud Chats

  1. If the user deletes the content in Telegram/*, the files will be re-downloaded again if he sees an image or an audio message. This can be prevented by disabling auto-downloads. After disabling auto-downloads, the user can manually remove files with a file explorer.
  2. Go into Settings - Apps - Telegram - Delete Cache to delete the content of Android/data/org.telegram.messenger/cache

Secret Chats

If the user deletes the cache (Android Settings » Apps » Telegram » Clear Cache), cached profile images and even files from Secret Chats are deleted. In the Secret Chat, the user will have to manually download each file again from the cloud.