I am trying to fill the internal storage memory . But my app crashes everytime I run it.
My logcat error is:
java.lang.NoSuchMethodError: android.os.Environment.isExternalStorageRemovable
at com.symbol.fillexternalmemory.MainActivity.getExternalSdCardSize(MainActivity.java:175)
at com.symbol.fillexternalmemory.MainActivity.onCreate(MainActivity.java:44)
My MainActivity.java is:
protected static Long getExternalSdCardSize() {
File storage = new File("/storage");
String external_storage_path = "";
Long size = null;
if (storage.exists()) {
File[] files = storage.listFiles();
for (File file : files) {
if (file.exists()) {
try {
if (Environment.isExternalStorageRemovable(file)) {
// storage is removable
external_storage_path = file.getAbsolutePath();
break;
}
} catch (Exception e) {
Log.e("TAG", e.toString());
}
}
}
}
if (!external_storage_path.isEmpty()) {
File external_storage = new File(external_storage_path);
if (external_storage.exists()) {
size = totalSize(external_storage);
}
}
return size;
}
And my build.gradle file is:
android {
compileSdkVersion 23
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.symbol.fillexternalmemory"
minSdkVersion 22
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:support-v4:23.4.0'
}
Can someone tell me why is it that the app crashes everytime? I have referred pervious answers to similar question but couldn't find a proper solution that helped?