Last active
December 22, 2019 21:34
-
-
Save john-lorrenz/01abd904f7992977928a5758faa4e174 to your computer and use it in GitHub Desktop.
Basic Permission Template - using florent library
This file contains hidden or 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
<uses-permission android:name="android.permission.INTERNET" /> | |
<uses-permission android:name="android.permission.READ_CONTACTS" /> | |
<uses-permission android:name="android.permission.CAMERA" /> | |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | |
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> |
This file contains hidden or 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
fun uriExposureFix(){ | |
var builder = StrictMode.VmPolicy.Builder() | |
StrictMode.setVmPolicy(builder.build()) | |
} | |
fun askPermission(){ | |
RuntimePermission.askPermission(this) | |
.request(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA) | |
.onAccepted{ | |
// DO YOUR ACTIONS HERE | |
// SAMPLE ACTION 1 | |
openGallery() | |
// SAMPLE ACTION 2 | |
openCamera() | |
} | |
.ask() | |
} | |
fun openGallery(){ | |
val intent = Intent(Intent.ACTION_PICK) | |
intent.type = "image/*" | |
startActivityForResult(intent, 0) | |
} | |
fun openCamera(){ | |
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
var file = File(this.externalCacheDir, "[FILE NAME]") | |
val imageUri = Uri.fromFile(file) | |
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri) | |
startActivityForResult(intent, [REQUEST CODE]) | |
} | |
This file contains hidden or 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
implementation 'com.github.florent37:runtime-permission:1.1.1' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment