mirror of
https://github.com/home-assistant/android
synced 2024-10-15 12:32:54 +00:00
Assistant app intent fallback to 'safe' intent if not found (#3654)
- It looks like not all devices keep the original settings names, fallback to the 'manage default apps' intent if we cannot directly open the screen for the assistant app setting
This commit is contained in:
parent
23c35af6a2
commit
dbae8d2613
|
@ -2,6 +2,7 @@ package io.homeassistant.companion.android.settings
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.UiModeManager
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
|
@ -344,12 +345,23 @@ class SettingsFragment(
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
private fun updateAssistantApp() {
|
||||
// On Android Q+, this is a workaround as Android doesn't allow requesting the assistant role
|
||||
val openIntent = Intent(Intent.ACTION_MAIN)
|
||||
openIntent.component = ComponentName("com.android.settings", "com.android.settings.Settings\$ManageAssistActivity")
|
||||
openIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
startActivity(openIntent)
|
||||
try {
|
||||
val openIntent = Intent(Intent.ACTION_MAIN)
|
||||
openIntent.component = ComponentName("com.android.settings", "com.android.settings.Settings\$ManageAssistActivity")
|
||||
openIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
startActivity(openIntent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
// The exact activity/package doesn't exist on this device, use the official intent
|
||||
// which sends the user to the 'Default apps' screen (one more tap required to change)
|
||||
startActivity(
|
||||
Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateBackgroundAccessPref() {
|
||||
|
|
Loading…
Reference in a new issue