Where does the metadata about downloaded files get stored? - android

An app named Downloads is present in the GINGERBREAD version of Android. It lists the files downloaded. Where are these files stored and are there any standard APIs to access the downloaded files?

os.Environment has a method called getDownloadCacheDirectory()
You can get a list of all the files in this directory as follows:
File downloadFolder = Environment.getDownloadCacheDirectory();
File[] downloadFiles = downloadFolder.listFiles();
Documentation from the Android developers site.

Related

After install app, Internal storage (Android>data) package folder not created

When I fresh install app, I notice most of the app will have a folder created in Internal Storage > Android > Data > com.example.package folder. For example its facebook app it will be something like com.facebook.xxxxx.
However, one of the project I involve recently, I notice there is no such app folder in the path Internal storage > Android > Data > (No packege folder).
In what scenario it won't create an app folder in the above path ? Because most of the app I debug run via android studio or install via apk file...Always have one app folder in the above location by default.
Because I want to write below file into getFilesDir(),
File file = new File(activity.getFilesDir(),imageFileName);
By using getFilesDir(), written file will go into Android > Data > Package folder > Files folder, most of the installed app have a package folder path in Android > Data > (Here). Today I realise one of the project I am doing now, it doesn't create such package folder. So, when I use getFilesDir() , those files will still be stored and created inside the mentioned path but it is invisible? Or Those files I create using getFilesDir() won't be created? Because as I mentioned this app doesn't create a package folder. Do I have to use makedir ? If yes what will be the checking ? if(!activity.getFilesDir(). exist())
File file = new File(activity.getFilesDir(),imageFileName);
//getFilesDir() normally is package folder Android > Data > (package folder*) > Files
I have tested and find out that if phone is having internal storage only (Not support SDCard) or maybe phone support external storage but don't have SDCard insert. App folder in this path by default won't be created (Android > Data > [App folder]), until I called (getExternalFilesDir(null) , "Example1") check its exists() and makedirs() if it doesn't exist, finally the app folder is created with a folder Example1 in this path Android > App > com.xxxxx.myapp > files > Example1.
However, why some sample app I create I never call getExternalFilesDir(null) or any File writing storage path but by default I can find my sample app path in Android > App > [Here].
Some app folder won't be created by default but until getExternalFilesDir(null) check exist and mkdirs then it become exist and created. Some app folder will be created when app is installed by default. How Android determine if the Android > App > App folder should be created and visible or created and make it invisible??
It makes me confuse. Some app will create app folder, some app wont create it by default when app is installed. Let's assume both app never call any File path create method. Just a very sample app I run using latest Android Studio to test something, it created package folder. The big project app is using old gradle settings and almost 5 years ago, the app by default won't create package folder until I call File(getExternalFilesDir(null), Example1) check if it exists and it doesn't then mkDirs(), package folder become created and visible.
How SY MY told you need to check if phone is having internal storage only (Not support SDCard) or maybe phone support external storage but don't have SDCard insert. App folder in this path by default won't be created. And how he checked you shoud make if statement. So... you can paste this code in your project:
File file = new File(getExternalFilesDir(null),fileName);
if (!file.exists()&&file.mkdirs()){
File file1 = new File(getFilesDir(), fileName);
}
fileName it is a String varable with txt foramt:
private String fileName = "list.txt";

Xamarin PCLStorage package: What is the root folder this PCLStorage reference to

I saw this package on Xamarin page. To access the file system I can use PCLStorage.FileStream.Current.localStorage to get the current root storage of the device but which folder it referring to on device: Is it the application private folder or somewhere else?
Can we access other folders e.g. On android, there DOCUMENT, DOWNLOAD folders?
PCLStorage source for LocalStorage:
#if ANDROID
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
#elif IOS
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
In Android this maps to the root of app's private storage, i.e.:
/data/data/{ApplicationID}/files
In iOS, this is mapped to the app's private Documents folder:
/data/data/{Package}/Documents
If your app requirements differ, you would need to mod the source of that project or provide your own platform code via a Xamarin.Forms dependency service.

Deleting file from internal storage

How do I delete a file or folder on the internal storage in android with Delphi for android
You should use the TFile and TDirectory classes in the System.IOUtils unit.
For example:
TDirectory.Delete(<YOUR DIR PATH>);
or
TFile.Delete(<YOUR FILE PATH>);
Look in Embarcadero's documentation to get the right path of your files and folders on the various platforms:
Standard RTL Path Functions across the Supported Target Platforms
Referred from :
https://stackoverflow.com/a/27047502/5193608
https://stackoverflow.com/a/3554949/5193608
Main Part from both links:
You should always delete files that you no longer need. The most straightforward way to delete a file is to have the opened file reference call delete() on itself.
myFile.delete();
If the file is saved on internal storage, you can also ask the Context to locate and delete a file by calling deleteFile():
myContext.deleteFile(fileName);
Note: When the user uninstalls your app, the Android system deletes the following: All files you saved on internal storage All files you saved on external storage using getExternalFilesDir(). However, you should manually delete all cached files created with getCacheDir() on a regular basis and also regularly delete other files you no longer need.
Source : http://developer.android.com/training/basics/data-storage/files.html
Directly you can do is :
File dir = getFilesDir();
File file = new File(dir, "my_filename");
boolean deleted = file.delete();
Hope,it helps!

Corona SDK: system.pathForFile returns nil

This code works in the simulator but not on my Android device:
local path = system.pathForFile("chinese_rules.db")
print("PATH:: " .. tostring( path ) )
When I run this code on my Galaxy S4 path returns nil.
My first thought was that it was some typo (case sensitivity) but I can't find any typo:
http://i59.tinypic.com/wlpu14.png
I can't find any reason why it should receive nil. This causes a problem as I can't load my database.
I have also tried this with the same result:
local path = system.pathForFile("chinese_rules.db", system.ResourceDirectory)
I have been able to load a path and load databases like this before.
Corona Build: 2013.2100 (2013.12.7)
Further reading the documentation I don't see that .db is a restricted file type:
Corona allows direct loading of images and audio files using the
appropriate APIs, but it has limited access to resource files on
Android using the file I/O APIs. Specifically, the following types can
not be read from the resources directory: .html, .htm., .3gp, .m4v,
.mp4,.png, .jpg, and .ttf.
http://docs.coronalabs.com/api/library/system/pathForFile.html
I found out the reason for the problem:
We are two that are working on this project and he had setup to use expansion files so two files was created (the main APK and the OBB expansion file) which I didn't notice and I only loaded the main APK file and I guess the database is in the OBB file. After setting not to use an expansion file the app works.
usesExpansionFile = false

Adobe Air for Android: Where is a xml file after instalation .apk file

An Air app which loading data from an external XML file (cfg.xml). I've published the Android/Air file, included the cfg.xml file in the Android package. Then I've installed on my SD Card(). App's reading xml file - working perfectly. But I need raw access(on my device) to cfg.xml I cannot find this file, checked everywhere(Rooted Phone). Where is it? Is there other solution? I need a file which is easy to read/write.
Use DDMS -> File Explorer and look for you app name in folders like data, ...
Solution:
Use fileStream instead of URLLoader
Change directory to SD Card e.g.
File.userDirectory.resolvePath("YourAppData/cfg.xml")
(No rooted phone needed)

Categories

Resources