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";
Related
In other Apps I can access files in directories like /storage/emulated/0/Android/data/com,xxx,yyy/files
In my own app I want to use it too. But with getApplicationInfo().dataDir I receive /data/user/0/com.xx.yy/files
How can I receive the path to /storage... and how to create this directory (it was not create automatically after installing the App)
Now I find out that getExternalFilesDir(null).getAbsolutePath() do the job
I've created an app which reads a text file created by an installed app. The location of this file is located at: This PC\Galaxy S4\Phone\veryfit2.2\file.txt.
I tried to get access to this file using Environment and getBaseContext(), but in both cases, it didn't help. How can I access the text file?
Here's the folder directory:
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!
How can I get path where my application is installed so I can access to raw folder and set some file as ringtone?
String path=android.os.Environment.getExternalStorageDirectory().getPath() + "sdcard/data/FunnySoundsz/res/raw/fusrodah.mp3";
But nothing happens with this. I set in my Manifest that app install only on Internal Storage
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)