Search code examples
androidexternal

Android Studio - How to use getExternalFilesDir


Since google killed the perfectly fine method getExternalStoragePublicDirectory, I have to try to get getExternalFilesDir to work.

This is one of the things I've tried:

private Context context = this.getApplicationContext();
private static final String test = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);

error message:

Non-static field 'context' cannot be referenced from a static context

I am not allowed to make context a static field though.


Solution

  • what is this reference to your activity, if yes then use:

    this.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);