When I use /storage/sdcard0/ on them the code runs successfully but when I use Galaxy Nexus 3 the code fails.
/storage/sdcard0/
is not internal storage. It is external storage.
(BTW, since there is no device named "Galaxy Nexus 3", I am assuming that you simply meant "Galaxy Nexus")
To find locations on internal storage for your app, use getFilesDir()
, called on any Context
(such as your Activity
, to get a File
object.
To get a location on external storage unique for your app, use getExternalFilesDir()
, called on any Context
(such as your Activity
, to get a File
object.
To get a standard location on external storage for common types of files (e.g., movies), use getExternalStoragePublicDirectory()
on Environment
.
To get the root of external storage, use getExternalStorageDirectory()
on Environment
. This, however, is considered sloppy programming nowadays, as it encourages developers to just put files in random locations.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…