Android: Trouble with Environment.DIRECTORY_DOWNLOADS in android 2.1
I have an app that will try and restore a database from the SD card on the first start after and data clear or reinstall. I have the data back saved to the Downloads directory on the SD Card. This works perfect for Android 2.2 and higher, but I'm running into problems with 2.1.1 and below. below is the line of code that is through the error.
File sdPath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) +
"/Android/data/com.company.appname/databases/");
The problem above is "Environment.DIRECTORY_DOWNLOADS". It said "DIRECTORY_DOWNLOADS cannot be resolved or is not a field" when i'm running it on And开发者_Go百科roid 2.1.1 and lower.
Thanks in advance for any help!
Environment.DIRECTORY_DOWNLOADS is first available in API 2.2. Instead, try:
File sdPath = new File(Environment.getExternalStoragePublicDirectory() +
"/Android/data/com.company.appname/databases/");
Since this may cause some trouble with getting database values, you may wish to consider dropping support for API 2.1 and below. Most users use API 2.2 and above anyways.
精彩评论