Get Android device/emulator root directory

2019-09-16 18:28发布

问题:

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

回答1:

You can see that http://developer.android.com/reference/android/os/Environment.html to get the "same" directory with getExternalStorageDirectory() method



回答2:

<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