Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android sync adapter with appengine Google user accounts

I am implementing a sync adapter for my app to sync with an appengine backend. On appengine I am using the built in User api for authentication. There is a post HERE that tells how to do it, however the app is listed under the gmail account. 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. 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. In the getAuthToken() methods I should be able to simple return the google auth token. Will post once I get further along...

like image 808
Patrick Avatar asked May 10 '12 00:05

Patrick


2 Answers

Perhaps you have misunderstood the Android account system. 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. 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. That sounds wrong to me. You'll end up reimplementing the Google account handling, with little value. 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 (e.g., manifest, activity layout, etc.).

like image 68
andyandy Avatar answered Oct 28 '22 06:10

andyandy


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

... don't forget to check the follow up in part 2

Beyond this there is also an example in the Android SDK samples called SampleSyncAdapter which was invaluable in my development.

With a little hard work and a lot of coffee you should be able to get this working ;)

like image 25
Moog Avatar answered Oct 28 '22 06:10

Moog