SD card detection fix

This commit is contained in:
GaidamakUA 2015-10-23 16:46:32 +03:00
parent 7e8ddaee17
commit 43cb1d98d1
3 changed files with 22 additions and 6 deletions

View file

@ -43,6 +43,8 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.text.TextUtils;
public class OsmandSettings {
@ -1308,6 +1310,21 @@ public class OsmandSettings {
putString(EXTERNAL_STORAGE_DIR_V19, externalStorageDir).commit();
}
@Nullable
public static File getSecondaryStorage() {
final String value = System.getenv("SECONDARY_STORAGE");
if (!TextUtils.isEmpty(value)) {
final String[] paths = value.split(":");
for (String path : paths) {
File file = new File(path);
if (file.isDirectory() && file.canWrite()) {
return file;
}
}
}
return null;
}
public void setExternalStorageDirectory(int type, String directory) {
if(Build.VERSION.SDK_INT < 19) {
setExternalStorageDirectoryPre19(directory);
@ -1325,7 +1342,6 @@ public class OsmandSettings {
return settingsAPI.edit(globalPreferences).putString(EXTERNAL_STORAGE_DIR, externalStorageDir).commit();
}
public Object getGlobalPreferences() {
return globalPreferences;
}

View file

@ -142,7 +142,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
}
final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(null);
final boolean externalExists =
DataStoragePlaceDialogFragment.getExternalStorageDirectory(this) != null;
DataStoragePlaceDialogFragment.getExternalStorageDirectory() != null;
if (firstTime && externalExists) {
new DataStoragePlaceDialogFragment().show(getFragmentManager(), null);
}

View file

@ -55,7 +55,7 @@ public class DataStoragePlaceDialogFragment extends DialogFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
internalStorage = getInternalStorageDirectory(getActivity());
externalStorage = getExternalStorageDirectory(getActivity());
externalStorage = getExternalStorageDirectory();
final View view = inflater.inflate(R.layout.fragment_data_storage_place_dialog, container,
false);
@ -95,9 +95,8 @@ public class DataStoragePlaceDialogFragment extends DialogFragment {
return view;
}
public static File getExternalStorageDirectory(Activity activity) {
return ((OsmandApplication) activity.getApplication()).getSettings()
.getExternalStorageDirectory();
public static File getExternalStorageDirectory() {
return OsmandSettings.getSecondaryStorage();
}
public static File getInternalStorageDirectory(Activity activity) {
@ -122,6 +121,7 @@ public class DataStoragePlaceDialogFragment extends DialogFragment {
String sz = "";
if (dir.canRead()) {
StatFs fs = new StatFs(dir.getAbsolutePath());
@SuppressWarnings("deprecation")
int size = fs.getAvailableBlocks() * fs.getBlockSize();
if (size > 0) {
if (size > 1 << 20) {