2

I'm using Android version is 4.2

I want to get the path of a stored file by using this

String file = Environment.getExternalFilesDir() + "/"+title+".zip" 

I get this error:

The method getExternalFilesDir() is undefined for the type Environment 

However, the Environment class does have this method, why do I get this error?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Jolin
  • 1,515
  • 4
  • 21
  • 24

1 Answers1

2

getExternalFilesDir() is a method of Context.

Environment has other methods, but not that one.

This answer explains the difference between them, also.

Community
  • 1
  • 1
Geobits
  • 22,218
  • 6
  • 59
  • 103
  • this is very weird, dont get it why google keep this method to `context` while other methods such as getExternalStoragePublicDirectory(),getExternalStorageDirectory() to Envirnoment. – Jolin Feb 16 '13 at 21:55
  • Probably because the `files` directory is application-specific, while regular external storage is available to all to read/write. – Geobits Feb 16 '13 at 21:56