Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mimic Context.getExternalFilesDir() prior to Android API Level 8?

Android API level 8 introduced the Context.getExternalFilesDir() method, providing a File object reference to an SD card path specific to your app. I am wondering how to mimic this as low as API level 5.

I see there is a Context.getDir() method, but I can't tell from reading about it how this differs.

like image 860
Matt Huggins Avatar asked Sep 21 '10 01:09

Matt Huggins


1 Answers

I ended up finding the answer here. Here's an excerpt from that page that answers my exact question:

If you're using API Level 7 or lower, use getExternalStorageDirectory(), to open a File representing the root of the external storage. You should then write your data in the following directory:

/Android/data/<package_name>/files/

The <package_name> is your Java-style package name, such as "com.example.android.app". If the user's device is running API Level 8 or greater and they uninstall your application, this directory and all its contents will be deleted.

like image 60
Matt Huggins Avatar answered Sep 26 '22 21:09

Matt Huggins