跨应用程序的 Android AccountManager : uninstalling the first app that registered the account causes the account to be deleted?

标签 android single-sign-on accountmanager

我们要实现的目标:跨应用单点登录

我们有 2 个应用程序(应用程序 A 和应用程序 B),我们希望共享同一个用户帐户。也就是说,当用户登录应用 A 时,他们将自动登录应用 B,反之亦然。

我们做了什么

我们创建了一个自定义身份验证器(扩展 AbstractAccountAuthenticator 等)以从我们的服务中检索身份验证 token ,以确保用户已登录到我们的应用程序。

我们将身份验证器拉入我们想要共享帐户的两个不同的应用程序(应用程序 A 和应用程序 B)。

我们安装了应用程序 A,并登录了。然后我们安装了应用程序 B,并看到我们已自动登录。耶!

但是,当我们随后卸载应用程序 A(我们安装的第一个应用程序)时,我们看到了以下消息:

03-20 16:43:27.057 862-862/? W/AccountManagerService:删除帐户 username@blah.com,因为类型 com.example.app.a 的注册身份验证器不再存在。

并看到我们将退出应用程序 B,并且该帐户已从帐户中消失。

问题是:唯一注册的账号认证器是第一个安装的吗?如果卸载了应用程序 A,是否无法回退到应用程序 B 中的帐户验证器?

(仅供引用:我们已经看到设置 sharedUserId 可以解决这个问题,但我们的应用程序目前正在运行,因此无法更改其 userId)

最佳答案

您可能想探索解决方案 suggested by Google in this article ,包括将您的身份验证器作为单独的 APK 分发:

If only one app will ever access the [account] service, then this isn't a big deal—just bundle the service in the app. But if you want your account service to be used by more than one app, things get trickier. You don't want to bundle the service with all of your apps and have multiple copies of it taking up space on your user's device.

One solution is to place the service in one small, special-purpose APK. When an app wishes to use your custom account type, it can check the device to see if your custom account service is available. If not, it can direct the user to Google Play to download the service. This may seem like a great deal of trouble at first, but compared with the alternative of re-entering credentials for every app that uses your custom account, it's refreshingly easy.

当您的用户卸载您的应用 A 和/或 B 时,身份验证器 APK 不会自动卸载。这意味着如果您的用户决定重新安装您的应用,则他们可能已经通过身份验证。这可能是可取的,也可能不是可取的,因为它会给您的用户带来负担,让他们在卸载您的应用后记住卸载身份验证器。

关于跨应用程序的 Android AccountManager : uninstalling the first app that registered the account causes the account to be deleted?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42923746/

相关文章:

android - 如何通过 Intent 将电话号码添加到现有联系人?

android - 如何在应用中高效实现多主题?

android - 如何使用最新的 facebook sdk 4.1.0 抑制单点登录

azure - Azure Active Directory 中的单点登录的自定义域为 "not planned"

android - 是什么保护 Android AccountManager 密码不被其他应用程序读取?

android - 自定义帐户身份验证器。从设备中删除帐户后的清理

android - authTokenType 到底是什么意思?

java - ReadObject 返回 OptionalDataException

android - appwidget 从不去 onUpdate

asp.net-mvc - 如何为本地 Web 应用程序配置 Azure AD 身份验证