Reputation: 1292
I am developing an Android application using Eclipse/Ubuntu. As usual, I am doing the first shot on an AVD emulator. I would like to put in place a unique folder structure that I can use on both the current emulator and on the final physical device (the SD memory card). What would be the Android environment variable to pick up the root directory by program (Java of course) for both type of virtual and physical devices, so that I can have my starting reference? Thanks PS: I have the DDMS File Explorer open, in case the answer refers to the structure there
Upvotes: 2
Views: 18793
Reputation: 18538
Environment.getExternalStorageDirectory()
is deprecated and Context#getExternalFilesDir(String), MediaStore, or Intent#ACTION_OPEN_DOCUMENT, should be used instead.
This method was deprecated in API level 29. To improve user privacy, direct access to shared/external storage devices is deprecated. When an app targets Build.VERSION_CODES.Q, the path returned from this method is no longer directly accessible to apps. Apps can continue to access content stored on shared/external storage by migrating to alternatives such as Context#getExternalFilesDir(String), MediaStore, or Intent#ACTION_OPEN_DOCUMENT.
https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()
Upvotes: 1
Reputation: 5819
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
You need user permission if you want to write in storage
File root = Environment.getExternalStorageDirectory();
This will create instance of your root directory
Upvotes: 2
Reputation: 9061
You can see that http://developer.android.com/reference/android/os/Environment.html to get the "same" directory with getExternalStorageDirectory()
method
Upvotes: 2