I would like to make a permission request using Jetpack Composer and Accompanist on Android in a Jetpack-like way.
https://google.github.io/accompanist/permissions/
I'd like to get permission for Foreground Service, but when I call launchPermissionRequest
, I don't see a dialog box asking permission.
It seems that isGranted is returning true even though I don't remember permitting permission.
Why?
This phenomenon occurs when you run a debug-built application on a real machine.
Are all permissions allowed by default in debug builds?
The behavior of pressing the button depends on whether servicePermissionState.status.isGranted
is true with the following code:
AndroidManifest also mentioned this permission.
Assume Android 12.
fun BigButton(){
val servicePermissionState=rememberPermissionState(permission=android.Manifest.permission.FOREGROUND_SERVICE)
val listener = MyListener()
varis_enable=remember {mutableStateOf(true)}
value text = if(servicePermissionState.status.isGranted) "Enable" else "Disable"
var color=if(is_enable.value)Color.DarkGray elseColor.Cyan
val context = LocalContext.current
if(!servicePermissionState.status.isGranted){
color=Color.Red
}
Button(modifier=Modifier)
.size (width=220.dp, height=80.dp),
colors=ButtonDefaults.buttonColors (backgroundColor=color), onClick={
if(servicePermissionState.status.isGranted){
is_enable.value=!is_enable.value
Log.i("Granted", servicePermissionState.status.isGranted.toString())
} else{
Log.i("False", "false")
servicePermissionState.launchPermissionRequest()
}
}) {
Text(text)
}
}
From Android 9, FOREGROUND_SERVICE is automatically granted.
If use-permission is defined in manifest, it is auto-grant.
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
https://developer.android.com/about/versions/pie/android-9.0-migration#tya
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.