I want to have a single folder where I will put all the resources I'm going to need and I want it on the internal storage. Since I want this directory to be created only once, I found out that I should create it in the main activity of the application:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
File directory = context.getDir("mydir", Context.MODE_PRIVATE);
Log.d("directory", directory.getAbsolutePath().toString());
}
It seems ok as this is what I was able to find on the internet, however I am receiving loads of erros, I can get to the log for the directory path and the application doesn't start. Any idea why?
Also, if I work with internal storage every time when I run my application from Eclipse to my phone, does it automatically deletes the previous one together with its resources or I've to do that manually?
use
getCacheDir()
. It returns the absolute path to the application specific cache directory on the filesystem. Then you can create your directoryI think Blackbelt answer is good but did not want to store it on internal cache (it will get erased and written to often that way for the specs I was trying to make) so what i did is:
And then
IF you would like to store on the external storage SD card instead, you need to have this
In your AndroidManifest.xml file
Also this for working with the storage:
First of all, make sure to read up on and understand the different storage options you have available for your application. Google has a very good article on the subject here:
http://developer.android.com/guide/topics/data/data-storage.html
The answer above from Andy mentions Environment.getExternalStorageDirectory() (API Level 7) for writing to an SD card or similar, but you should keep in mind that files written to that location will not get deleted when the user uninstalls the app. The documentation says:
"Applications should not directly use this top-level directory, in order to avoid polluting the user's root namespace"
Instead, if you target API Level 8 and above, you should use Context.getExternalCacheDir() as files in that location will get removed when the app is uninstalled. If you really want files to persist even after an uninstall you should use Context.getExternalFilesDir(). There's also getCacheDir() and getFilesDir() for working with files on the internal storage.
As was mentioned in the comments to your question you really should post the errors here for us to be able to help you.
PS I'm new to answering questions on SO so I don't have enough rep to post links to all of the functions mentioned in my answer and I do not seem able to comment on previous posts.
Android studio Download video in specific folder: