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.ACCESS_COARSE_LOCATION"/> | |
<uses-permission android:name="android.permission.READ_CALENDAR"/> | |
<uses-permission android:name="android.permission.READ_CONTACTS"/> | |
<uses-permission android:name="android.permission.RECORD_AUDIO"/> |
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
enum class NeededPermission( | |
val permission: String, | |
val title: String, | |
val description: String, | |
val permanentlyDeniedDescription: String, | |
) { | |
COARSE_LOCATION( | |
permission = android.Manifest.permission.ACCESS_COARSE_LOCATION, | |
title = "Approximate Location Permission", | |
description = "This permission is needed to get your approximate location. Please grant the permission.", |
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
@Composable | |
fun PermissionAlertDialog( | |
neededPermission: NeededPermission, | |
isPermissionDeclined: Boolean, | |
onDismiss: () -> Unit, | |
onOkClick: () -> Unit, | |
onGoToAppSettingsClick: () -> Unit, | |
) { | |
AlertDialog( |
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
@Composable | |
fun Permissions() { | |
val activity = LocalContext.current as Activity | |
val permissionDialog = remember { | |
mutableStateListOf<NeededPermission>() | |
} | |
val microphonePermissionLauncher = rememberLauncherForActivityResult( |
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
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
PermissionHandlingTheme { | |
// A surface container using the 'background' color from the theme | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colors.background | |
) { |
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.google.android.gms:play-services-location:21.0.1' | |
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.4' |
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.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
class LocationService { | |
@SuppressLint("MissingPermission") | |
suspend fun getCurrentLocation(context: Context): Location { | |
if (!context.hasPermissions( | |
Manifest.permission.ACCESS_FINE_LOCATION, | |
Manifest.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
@Composable | |
fun GetCurrentLocationUI() { | |
var currentLocation by remember { | |
mutableStateOf("") | |
} | |
val scope = rememberCoroutineScope() | |
val context = LocalContext.current | |
val permissionRequest = rememberLauncherForActivityResult( | |
contract = ActivityResultContracts.RequestMultiplePermissions(), |
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
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
GetCurrentLocationUI() | |
} | |
} | |
} |
OlderNewer