Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

Android getting external storage Absolute Path

I want to download some files and save them into the internal storage of the phone/tab. Tried on Samsung Galaxy Note 2 and Galaxt Tab 10.1. When I use /storage/sdcard0/ on them the code runs successfully but when I use Galaxy Nexus 3 the code fails.

I want to get absolute path of the phoe or tab's internal storage' Absolute Path.

Does it possible, if so how?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...