I tried showing an alert dialog over other apps. The permissions are granted.
<uses-permission android:name="ACTION_MANAGE_OVERLAY_PERMISSION"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
The Composable way is not working at all, codes follow:
AlertDialog(onDismissRequest = { dialogEnabled.value = false },
title = { Text(text = "Test")},
text = {
Text(text = message)
},
confirmButton = {
TextButton(onClick = { dialogEnabled.value = false }) {
Text(text = "Confirm")
}
},
dismissButton = {
TextButton(onClick = { dialogEnabled.value = false }) {
Text(text = "Cancel")
}
}
)
I got to set the type of the AlertDialog's window to WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY. However, I view the code of AlertDialog under AndroidDialog.android.kt, there no way to get the reference of dialog instance, not even the DialogProperty.
Eventually, I got use the traditional way to achieve it
private fun showDialog(message: String){
val builder: AlertDialog.Builder = AlertDialog.Builder(this) //set icon
.setIcon(android.R.drawable.ic_dialog_alert) //set title
.setTitle("Game Analysis") //set message
.setMessage(message) //set positive button
.setPositiveButton(
"Confrim"
) { dialogInterface, i -> //set what would happen when positive button is clicked
dialogInterface.dismiss()
} //set negative button
.setNegativeButton(
"Cancel"
) { dialogInterface, i -> //set what should happen when negative button is clicked
dialogInterface.dismiss()
}
val alertDialog: AlertDialog = builder.create()
alertDialog.window!!.setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY)
alertDialog.show()
}