Skip to content

Commit

Permalink
Assistant app intent fallback to 'safe' intent if not found (#3654)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jpelgrom committed Jul 11, 2023
1 parent 23c35af commit dbae8d2
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit dbae8d2

Please sign in to comment.