Neoh
Neoh

Reputation: 16174

Should I save external data in directory Android/data or data/?

Which is correct,

String filePath = Environment.getExternalStorageDirectory()
                      + "/data/com.packagename";

or

String filePath = Environment.getExternalStorageDirectory()
                      + "/Android/data/com.packagename";

if I want to store data in external storage? I see many apps are using the second option, but some use the first path.

Upvotes: 1

Views: 1463

Answers (1)

Blackbelt
Blackbelt

Reputation: 157487

You should rely on the API to figure out the directory for you:

File externalDir = Context.getExternalFilesDir(null);

Context.getExternalFilesDir will return your 2nd path. Programs that return the 1st path probably hardcoded the path and got it wrong as a result.

Upvotes: 3

Related Questions