Robert
Robert

Reputation: 10943

Android reading SD External is not working

I am trying to read some files from my external SD.

final File externalStorage =  Environment.getExternalStorageDirectory();

String list = "";//
list+= "Listing all the files in SD: "  + externalStorage.getAbsolutePath() + "\n";
Log.i("VVV", list);

for (File file: externalStorage.listFiles()) {
    Log.i("VVV", file.getAbsolutePath());
    list += file.getAbsolutePath() + "\n";
}

I am trying to read my external SD. I do not why always get the /emulate/0 path instead of /storage/sdcard.

it is the output for the above code:

01-22 19:07:55.852 23991-23991/forkandjoin.tvplayer I/VVV: Listing all the files in SD: /storage/emulated/0
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Samsung
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/.face
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Music
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Podcasts
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Ringtones
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Alarms
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Notifications
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Pictures
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Movies
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Download
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/DCIM
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Documents
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Android
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/SMemo
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/ATT Locker
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/.wildtangent
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/.profig.os
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/WhatsApp
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/com.facebook.orca
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/.thumbnails
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Facebook Messenger
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/PhotoEditor
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/.facebook_cache
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Playlists
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/wdh_update
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/Skai
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/com.qisi.sdk.file
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/fujifilm
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/com.facebook.katana
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/IMO
01-22 19:07:55.862 23991-23991/forkandjoin.tvplayer I/VVV: /storage/emulated/0/ialog.txt

So I do not know what am I doing wrong?

Upvotes: 1

Views: 145

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006704

External storage is not removable storage. Your code is accessing external storage. You do not have filesystem access to arbitrary locations on removable storage. You are welcome to use the Storage Access Framework to ask the user to open a document, and the user can choose a document on removable storage.

Upvotes: 1

Related Questions