I am responsible for small problems in our company for the Android App since I am not such a good coder, iam a Sys Admin but iam like an Allrounder. Before we consider paying for a coder I want to fix this problem myself. I would benefit from fixing this too said my Chef =) Since the release of Android 14, our auto-grant permission after enabling the Accessibility of the App doesn't work anymore. We are around 130 peoples and more then the half have now Android 14.
When enabling Accessibility for the App the Permission Dialogs appear and should auto-grant the three Permissions. The Permisions are Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS. We write with our Database always new Contacts to the Phones and we need to read them in special cases, the main thing is just to write contacts on phones.
For auto-grant Permissions ill use the resource-id of the buttons. Because it doesnt work on Android 14 anymore i tried to use the text of the buttons which should be clicked when the text like "Grant" is found. In two languages i wrote the text of the Buttons but that doesnt work too.
I don't understand why it doesnt work anymore on A14, since the resource-id of the permission dialog the Button "Grant" is the same and has not been changed from A13. I viewed the resource-ids with the tool uiautomatorview which is present in the Android SDK. I can see that it "tries" to click on the button when the permission dialog appears but it doesn't happen.
Here are some code snippets for this: it's written in Kotlin. on one file i have the Permissions set:
val PERMISSIONS = arrayOf(
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.READ_CONTACTS,
Manifest.permission.WRITE_CONTACTS,
and this is the "click" code:
private fun AccessibilityServiceQ.click(it: AccessibilityNodeInfo, clickOnlyIfVisible: Boolean = false): Boolean {
runCatching {
if (clickOnlyIfVisible && it.isVisibleToUser) {
Log.v(TAG, "ACC::onAccessibilityEvent: click - $it")
return it.performAction(AccessibilityNodeInfo.ACTION_CLICK)
} else if (!clickOnlyIfVisible) {
Log.v(TAG, "ACC::onAccessibilityEvent: click - $it")
return it.performAction(AccessibilityNodeInfo.ACTION_CLICK)
}
}
}
this is the code for the resource-ids of the buttons that should be clicked when found:
private fun permissionClick(packageName: String, currentActivity: String, listWithNameOfApp: Set<AccessibilityNodeInfo>): Boolean {
val buttonIds = listOf(
"com.android.permissioncontroller:id/permission_allow_foreground_only_button",
"com.android.permissioncontroller:id/permission_allow_button")
and here is the code that is responsible for doing the click when the permission dialog appears: ` findAccessibilityNodeInfosByText is just there because i tried too like i said to use the text of the buttons, you can ignore that
fun clickOnButton(selector: String, findByText: Boolean): Boolean {
val nodes = if (findByText) {
eventRootInActiveWindow?.findAccessibilityNodeInfosByText(selector)
} else {
eventRootInActiveWindow?.findAccessibilityNodeInfosByViewId(selector)
}
return nodes?.firstOrNull { it.isClickable }?.let { node ->
click(node).also { node.recycle() }
} ?: false
That's everything I think. Why doesn't it work on Android 14 even if the resource-id is the same?
Can anybody help me here, please? We want to make the App easily installable and accessible so that no problems occurs or questions, we know all, that many people don't know what they do.
Hope for any Help if its even possible of course
regards