# HG changeset patch # User Xeli # Date 1314385403 -7200 # Node ID b13d1897d06fd1cbb8e019a0ffe3f207f0aceba9 # Parent 45618bdce725e810809dbc5c5a3ad89039f16d21 Made getDownloadPath compatible with < Froyo devices diff -r 45618bdce725 -r b13d1897d06f project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/Utils.java --- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/Utils.java Fri Aug 26 18:24:29 2011 +0200 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/Utils.java Fri Aug 26 21:03:23 2011 +0200 @@ -28,6 +28,8 @@ import android.content.Context; import android.content.res.TypedArray; +import android.os.Build; +import android.os.Environment; import android.widget.Toast; public class Utils { @@ -39,11 +41,32 @@ * @return absolute path */ public static String getDownloadPath(Context c){ - File f = c.getExternalCacheDir(); - if(f != null){ - return f.getAbsolutePath() + "/Data/"; + if(Build.VERSION.SDK_INT < 8){//8 == Build.VERSION_CODES.FROYO + return PreFroyoSDCardDir.getDownloadPath(c); }else{ - Toast.makeText(c, R.string.sdcard_not_mounted, Toast.LENGTH_LONG); + return FroyoSDCardDir.getDownloadPath(c); + } + } + + static class FroyoSDCardDir{ + public static String getDownloadPath(Context c){ + File f = c.getExternalCacheDir(); + if(f != null){ + return f.getAbsolutePath() + "/Data/"; + }else{ + Toast.makeText(c, R.string.sdcard_not_mounted, Toast.LENGTH_LONG).show(); + return null; + } + } + } + + static class PreFroyoSDCardDir{ + public static String getDownloadPath(Context c){ + if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ + if(Environment.getExternalStorageDirectory() != null) + return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Hedgewars/"; + } + Toast.makeText(c, R.string.sdcard_not_mounted, Toast.LENGTH_LONG).show(); return null; } }