我已将 AbstractAccountAuthenticator 实现为使用 SyncAdapter 的要求,但我的应用程序一次仅支持 1 个帐户。
当用户尝试通过设置添加另一个帐户时 - 设置崩溃并出现停止工作的错误。
我见过一些应用程序,例如LinkedIn、Facebook,它们以不同的方式处理它向用户显示吐司消息,并声明只支持一个帐户。我怎样才能实现这个功能?
这是我的验证器
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)
}
}