Я реализовал AbstractAccountAuthenticator как требование для использования SyncAdapter, поскольку мое приложение поддерживает только 1 учетную запись одновременно.
Когда пользователь пытается добавить другую учетную запись через настройки - Настройки вылетают с ошибкой, что он перестал работать.
Я видел какое-то приложение, например LinkedIn, Facebook, они как-то обрабатывают его по-разному, пользователю показывается тостовое сообщение с заявлением, что поддерживается только 1 учетная запись.Как я могу достичь этой функциональности?
Это мой аутентификатор
class ApplicationAuthenticator(private val context: Context) : AbstractAccountAuthenticator(context) {
// Editing properties is not supported
@Throws(UnsupportedOperationException::class)
override fun editProperties(response: AccountAuthenticatorResponse,
accountType: String): Bundle? {
throw UnsupportedOperationException()
}
// Don't add additional accounts
override fun addAccount(response: AccountAuthenticatorResponse, accountType: String,
authTokenType: String, features: Array<String>,
options: Bundle): Bundle? {
return bundleOf(AccountManager.KEY_INTENT to null)
}
// Ignore attempts to confirm credentials
@Throws(NetworkErrorException::class)
override fun confirmCredentials(response: AccountAuthenticatorResponse, account: Account,
options: Bundle): Bundle? {
return null
}
// Getting an authentication token is not supported
@Throws(NetworkErrorException::class, UnsupportedOperationException::class)
override fun getAuthToken(response: AccountAuthenticatorResponse, account: Account,
authTokenType: String, loginOptions: Bundle): Bundle? {
throw UnsupportedOperationException()
}
// Getting a label for the auth token is not supported
override fun getAuthTokenLabel(authTokenType: String): String {
return context.resources.getString(R.string.application_name)
}
// Updating user credentials is not supported
override fun updateCredentials(response: AccountAuthenticatorResponse, account: Account,
authTokenType: String, loginOptions: Bundle): Bundle? {
return null
}
// Checking features for the account is not supported
@Throws(NetworkErrorException::class)
override fun hasFeatures(response: AccountAuthenticatorResponse, account: Account,
features: Array<String>): Bundle {
return bundleOf(KEY_BOOLEAN_RESULT to false)
}
}