https://github.com/js-bhavyansh/permissions_handling
A Jetpack Compose Android app to request and handle camera and microphone permissions.
https://github.com/js-bhavyansh/permissions_handling
android camera compose-ui jetpack-compose kotlin kotlin-android microphone permissions-android viewmodel
Last synced: about 2 months ago
JSON representation
A Jetpack Compose Android app to request and handle camera and microphone permissions.
- Host: GitHub
- URL: https://github.com/js-bhavyansh/permissions_handling
- Owner: js-bhavyansh
- Created: 2024-07-16T01:28:15.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-16T02:25:52.000Z (almost 2 years ago)
- Last Synced: 2025-03-12T17:15:35.433Z (over 1 year ago)
- Topics: android, camera, compose-ui, jetpack-compose, kotlin, kotlin-android, microphone, permissions-android, viewmodel
- Language: Kotlin
- Homepage:
- Size: 105 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Permissions Handling App
This is a sample Android app that demonstrates how to request camera and microphone permissions using Jetpack Compose.
## Features
- Requests camera and microphone permissions.
- Shows a dialog when permissions are denied.
- Navigates to app settings when permissions are permanently denied.
## Screenshots
## Installation
1. Clone the repository:
```bash
git clone https://github.com/Bhavyansh03-tech/Permissions_Handling.git
```
2. Open the project in Android Studio.
3. Build and run the app on your Android device or emulator.
## Code Highlights
### Asking Permission If Denied Twice
If the user denies the permission twice, a dialog is shown to explain why the permissions are needed.
```kotlin
permissions.forEach { permission ->
val isGranted =
checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED
// If Permission is not granted :->
if (!isGranted) {
if (shouldShowRequestPermissionRationale(permission)) {
// If user decline permission 2 times which case should show when request permission.
// Directly show dialog :->
mainViewModel.updateShowDialog(true)
} else {
// Ask for permission :->
permissionsResultActivityLauncher.launch(permissions)
}
}
}
```
## Showing a Dialog When Permissions Are Denied
The app displays a dialog to inform the user about the need for permissions and provides an option to go to the app settings if the permissions were permanently denied.
```kotlin
if (showDialog) {
PermissionDialog(
onDismiss = {
mainViewModel.updateShowDialog(false)
},
onConfirm = {
mainViewModel.updateShowDialog(false)
if (launchAppSettings){
// In case you want to ask permission through app settings :->
Intent(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", packageName, null)
).also {
startActivity(it)
}
mainViewModel.updateLaunchAppSettings(false)
} else {
// In case you want to ask permission through dialog :->
permissionsResultActivityLauncher.launch(permissions)
}
}
)
}
```
## Contributing
Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.
1. Fork the repository.
2. Create your feature branch (`git checkout -b feature/your-feature`).
3. Commit your changes (`git commit -am 'Add some feature'`).
4. Push to the branch (`git push origin feature/your-feature`).
5. Create a new Pull Request.
## Contact
For questions or feedback, please contact [@Bhavyansh03-tech](https://github.com/Bhavyansh03-tech).
---