|
47 | 47 | import org.catrobat.catroid.io.StorageHandler;
|
48 | 48 | import org.catrobat.catroid.ui.dialogs.ErrorDialogFragment;
|
49 | 49 |
|
| 50 | +import android.app.Activity; |
50 | 51 | import android.app.AlertDialog;
|
51 | 52 | import android.app.AlertDialog.Builder;
|
52 | 53 | import android.content.Context;
|
@@ -81,30 +82,22 @@ public class Utils {
|
81 | 82 | public static final int FILE_INTENT = 2;
|
82 | 83 | private static boolean isUnderTest;
|
83 | 84 |
|
84 |
| - public static boolean hasSdCard() { |
85 |
| - return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); |
| 85 | + public static boolean externalStorageAvailable() { |
| 86 | + String externalStorageState = Environment.getExternalStorageState(); |
| 87 | + return externalStorageState.equals(Environment.MEDIA_MOUNTED) |
| 88 | + && !externalStorageState.equals(Environment.MEDIA_MOUNTED_READ_ONLY); |
86 | 89 | }
|
87 | 90 |
|
88 |
| - /** |
89 |
| - * Checks whether the current device has an SD card. If it has none an error |
90 |
| - * message is displayed and the calling activity is finished. A |
91 |
| - * RuntimeException is thrown after the call to Activity.finish; find out |
92 |
| - * why! |
93 |
| - * |
94 |
| - * @param context |
95 |
| - */ |
96 |
| - public static boolean checkForSdCard(final Context context) { |
97 |
| - if (!hasSdCard()) { |
| 91 | + public static boolean checkForExternalStorageAvailableAndDisplayErrorIfNot(final Context context) { |
| 92 | + if (!externalStorageAvailable()) { |
98 | 93 | Builder builder = new AlertDialog.Builder(context);
|
99 | 94 |
|
100 | 95 | builder.setTitle(context.getString(R.string.error));
|
101 |
| - builder.setMessage(context.getString(R.string.error_no_sd_card)); |
| 96 | + builder.setMessage(context.getString(R.string.error_no_writiable_external_storage_available)); |
102 | 97 | builder.setNeutralButton(context.getString(R.string.close), new OnClickListener() {
|
103 | 98 | @Override
|
104 | 99 | public void onClick(DialogInterface dialog, int which) {
|
105 |
| - // finish parent activity |
106 |
| - // parentActivity.finish(); |
107 |
| - System.exit(0); |
| 100 | + ((Activity) context).moveTaskToBack(true); |
108 | 101 | }
|
109 | 102 | });
|
110 | 103 | builder.show();
|
|
0 commit comments