check android version too ad editing SD card content

This commit is contained in:
tibbi 2016-11-05 16:09:01 +01:00
parent e511702fd5
commit b3e0dceff6
2 changed files with 6 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.filemanager
import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.support.v4.content.ContextCompat
import android.widget.Toast
import com.simplemobiletools.filepicker.extensions.getSDCardPath
@ -31,7 +32,11 @@ object Utils {
return matcher.matches()
}
fun needsStupidWritePermissions(context: Context, path: String) = isPathOnSD(context, path) && isKitkat()
fun isPathOnSD(context: Context, path: String): Boolean {
return path.startsWith(context.getSDCardPath())
}
fun isKitkat() = Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT
}

View File

@ -136,7 +136,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
fun checkStupidAndroidFiveSDCardWritePermission(pickedPath: String): Boolean {
val file = File(pickedPath)
return if (!file.canWrite() && Utils.isPathOnSD(applicationContext, pickedPath) && mConfig.treeUri.isEmpty()) {
return if (!file.canWrite() && Utils.needsStupidWritePermissions(applicationContext, pickedPath) && mConfig.treeUri.isEmpty()) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
startActivityForResult(intent, OPEN_DOCUMENT_TREE)
false