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 hasCameraPermission() = ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED |
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 createImageFile(): File { | |
| val timeStamp = SimpleDateFormat.getDateTimeInstance().format(Date()) | |
| val storageDir = getPicturesDirectory() | |
| return File.createTempFile( | |
| "JPEG_${timeStamp}_", | |
| ".jpg", | |
| storageDir | |
| ).apply { | |
| currentImagePath = absolutePath |
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
| private val requestSinglePermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted -> | |
| if (isGranted) { | |
| showToast("Permission Granted.") | |
| //Do something | |
| } else { | |
| showToast("Permission Denied.") | |
| //crying mainly I'd imagine | |
| } | |
| } |
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
| private val requestMultiplePermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { resultsMap -> | |
| resultsMap.forEach { | |
| Log.i(TAG, "Permission: ${it.key}, granted: ${it.value}") | |
| } | |
| } |
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 createImageFile(): File { | |
| val timeStamp = SimpleDateFormat.getDateTimeInstance().format(Date()) | |
| val storageDir = getPicturesDirectory() | |
| return File.createTempFile( | |
| "JPEG_${timeStamp}_", | |
| ".jpg", | |
| storageDir | |
| ).apply { | |
| currentImagePath = absolutePath |
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
| private val getCameraImage = registerForActivityResult(ActivityResultContracts.TakePicture()) { success -> | |
| if (success) { | |
| Log.i(TAG, "Got image at: $uri") | |
| //Do something with the image uri, go nuts! | |
| } | |
| } |
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
| requestMultiplePermissionLauncher.launch(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)) |
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
| dependencies { | |
| def activity_version = "1.2.0-beta01" | |
| // Java language implementation | |
| implementation "androidx.activity:activity:$activity_version" | |
| // Kotlin | |
| implementation "androidx.activity:activity-ktx:$activity_version" | |
| } |
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
| dependencies { | |
| def fragment_version = "1.3.0-beta01" | |
| // Java language implementation | |
| implementation "androidx.fragment:fragment:$fragment_version" | |
| // Kotlin | |
| implementation "androidx.fragment:fragment-ktx:$fragment_version" | |
| } |
OlderNewer