Better external storage management

This commit is contained in:
shagr4th 2013-10-29 00:25:58 +01:00
parent 332888b8c5
commit e3f8cdded1
3 changed files with 16 additions and 6 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.ab.x48" android:installLocation="auto" android:versionCode="53" android:versionName="1.53">
package="org.ab.x48" android:installLocation="auto" android:versionCode="54" android:versionName="1.54">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".X48"
android:label="@string/app_name"

View file

@ -13,9 +13,9 @@ import android.util.Log;
public class AssetUtil {
public static void copyAsset(Context context, AssetManager am, boolean force) {
File newDir = context.getExternalFilesDir(null);
File newDir = getSDDir(context);
File sd = Environment.getExternalStorageDirectory();
if (sd.exists() && sd.isDirectory() && newDir.exists() && newDir.isDirectory()) {
if (sd != null && sd.exists() && sd.isDirectory() && newDir.exists() && newDir.isDirectory()) {
File hpDir = new File(sd, ".hp48");
if (hpDir.exists()) {
File allFiles [] = hpDir.listFiles();
@ -35,7 +35,13 @@ public class AssetUtil {
}
public static File getSDDir(Context context) {
return context.getExternalFilesDir(null);
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
// We can read and write the media
return context.getExternalFilesDir(null);
} else {
// Load another directory, probably local memory
return context.getFilesDir();
}
}
private static void copyAsset(AssetManager am, File rep, boolean force) {
@ -80,7 +86,7 @@ public class AssetUtil {
}
public static boolean isFilesReady(Context context) {
File hpDir = context.getExternalFilesDir(null);
File hpDir = getSDDir(context);
if (!hpDir.exists() || !hpDir.isDirectory()) {
return false;
}

View file

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.ViewGroup;
@ -41,7 +42,10 @@ public class ProgListView extends ListActivity {
// go to the root directory
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
String last_dir = sp.getString("last_dir", "/sdcard");
String defaultPath = "/";
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
defaultPath = Environment.getExternalStorageDirectory().getAbsolutePath();
String last_dir = sp.getString("last_dir", defaultPath);
showDirectory(last_dir);
}