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?
With your document open, click File > Save As. Under Save As, select where you want to create your new folder. You might need to click Browse or Computer, and navigate to the location for your new folder. In the Save As dialog box that opens, click New Folder.
Internal storage directories: These directories include both a dedicated location for storing persistent files, and another location for storing cache data. The system prevents other apps from accessing these locations, and on Android 10 (API level 29) and higher, these locations are encrypted.
Head to Settings > Storage > Other and you'll have a full list of all the files and folders on your internal storage.
use getCacheDir()
. It returns the absolute path to the application specific cache directory on the filesystem. Then you can create your directory
File myDir = new File(getCacheDir(), "folder");
myDir.mkdir();
IF you would like to store on the external storage SD card instead, you need to have this
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
In your AndroidManifest.xml file
Also this for working with the storage:
File direct = new File(Environment.getExternalStorageDirectory()+"/folder");
if(!direct.exists()) {
if(direct.mkdir()); //directory is created;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With