简体   繁体   English

带有appengine Google用户帐户的Android同步适配器

[英]Android sync adapter with appengine Google user accounts

I am implementing a sync adapter for my app to sync with an appengine backend. 我正在为我的应用实现同步适配器以与appengine后端同步。 On appengine I am using the built in User api for authentication. 在appengine上我使用内置的User api进行身份验证。 There is a post HERE that tells how to do it, however the app is listed under the gmail account. 有一个帖子这里告诉你如何做到这一点,但是应用程序是在Gmail帐户下。 Ideally my app would be listed in the accounts. 理想情况下,我的应用程序将列在帐户中。 I don't want to ask the user for username and password, just use the existing google account for authentication. 我不想要求用户输入用户名和密码,只需使用现有的Google帐户进行身份验证即可。 Has anyone done this before?? 有没有人这样做过?

Update: I've been working on this and it looks like I could implement the AuthenticationService and store the users account name and leave the password as an empty string. 更新:我一直在努力,看起来我可以实现AuthenticationService并存储用户帐户名并将密码保留为空字符串。 In the getAuthToken() methods I should be able to simple return the google auth token. 在getAuthToken()方法中,我应该能够简单地返回google身份验证令牌。 Will post once I get further along... 一旦我进一步发展就会发布...

Perhaps you have misunderstood the Android account system. 也许你误解了Android帐户系统。 When you go to Settings -> Accounts & Sync and add a new account what you see then is a list of account types . 当您转到设置 - >帐户和同步并添加新帐户时,您会看到一个帐户类型列表。 Often there is a relationship between account types and apps, for example Facebook accounts are used together with Facebook. 通常,帐户类型和应用程序之间存在关系,例如Facebook帐户与Facebook一起使用。 Normally you would add a new account type if you have a different backend system for handling authentication etc. 通常,如果您使用不同的后端系统来处理身份验证等,则会添加新的帐户类型。

If I understand you correctly, you use Google accounts but want it to appear as your own account type. 如果我理解正确,您可以使用Google帐户,但希望它显示为您自己的帐户类型。 That sounds wrong to me. 这对我来说听起来不对。 You'll end up reimplementing the Google account handling, with little value. 您最终会重新实现Google帐户处理,几乎没有价值。 I believe it is simpler for users if you simply piggyback on what Google provides you with. 我相信如果您只是依靠谷歌提供给您的东西,它对用户来说更简单。 Your app / service / content provider can be seen when clicking on the account. 点击该帐户可以看到您的应用/服务/内容提供商。 For example, after installing "Tasks" by "Team Task" (disclaimer: I'm not affiliated with that company) they add "Sync Tasks" to the list of data & sync options. 例如,在通过“团队任务”安装“任务”后(免责声明:我不隶属于该公司),他们将“同步任务”添加到数据和同步选项列表中。

But if you really want to create your own account type, follow the sample Sample Sync Adapter . 但是,如果您确实要创建自己的帐户类型,请按照示例同步适配器示例进行操作。 Look for the Authenticator code and related resources (eg, manifest, activity layout, etc.). 查找Authenticator代码和相关资源(例如,清单,活动布局等)。

This is indeed possible and I have implemented this with success but be warned it is a bit of a headache. 这确实是可能的,我已经成功实现了这一点,但要警告它有点令人头疼。

There is an excellent tutorial available called writing-an-android-sync-provider-part-1 有一个很好的教程叫做write-an-android-sync-provider-part-1

... don't forget to check the follow up in part 2 ...不要忘记检查第2部分的后续行动

Beyond this there is also an example in the Android SDK samples called SampleSyncAdapter which was invaluable in my development. 除此之外,Android SDK样本中还有一个名为SampleSyncAdapter的示例,这在我的开发中非常宝贵。

With a little hard work and a lot of coffee you should be able to get this working ;) 通过一点努力和大量的咖啡,您应该能够使这个工作;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM