Created
March 1, 2019 02:50
-
-
Save DiegoGSantos/cea887e02db0da73788dfd9cc64fef8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.Manifest | |
import android.app.Activity | |
import android.content.pm.PackageManager | |
import android.os.Build | |
import android.support.v4.app.ActivityCompat | |
class PermissionManager { | |
fun isStoragePermissionGranted(context: Activity): Boolean { | |
return if (Build.VERSION.SDK_INT >= 23) { | |
isPermissionGranted(context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) | |
} else { | |
true | |
} | |
} | |
fun isPermissionGranted(grantResult: Int): Boolean { | |
return grantResult == PackageManager.PERMISSION_GRANTED | |
} | |
fun askForPermission(activity: Activity) { | |
ActivityCompat.requestPermissions(activity, arrayOf<String>(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment