Created
May 15, 2021 16:41
-
-
Save InsanusMokrassar/dfd73a73b1a1da2b4166e87ff034cfc5 to your computer and use it in GitHub Desktop.
Android contract to request permission for all files access getting
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.content.Context | |
import android.content.Intent | |
import android.os.Build | |
import android.os.Environment | |
import android.provider.Settings | |
import androidx.activity.result.contract.ActivityResultContract | |
import androidx.annotation.RequiresApi | |
@RequiresApi(Build.VERSION_CODES.R) | |
object RequestAccessToAllFilesContract : ActivityResultContract<Unit, Boolean>() { | |
override fun createIntent(context: Context, input: Unit?): Intent { | |
return Intent( | |
Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION | |
) | |
} | |
override fun parseResult(resultCode: Int, intent: Intent?): Boolean { | |
return Environment.isExternalStorageManager() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment