7

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...

Community
  • 1
  • 1
Patrick Jackson
  • 18,766
  • 22
  • 81
  • 141

2 Answers2

3

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.).

tomrozb
  • 25,773
  • 31
  • 101
  • 122
andyandy
  • 898
  • 8
  • 15
  • I understand what you are saying, however I will be syncing data that is specific to my app and the users account. It makes sense to put the "sync tasks" under the google account as it is google data that is being synced. I am using google accounts for login and account username purposes because the user will not have to remember another password and it reduces my workload – Patrick Jackson May 22 '12 at 13:48
  • I still think it would be best to add your app's data as part of users' google account. However, since you disagree feel free to implement a custom authenticator for your app. It is fairly easy by following the Sample sync adapter example and use Google Accounts as the server side (or, perhaps it is possible to use your appengine as a mediator for authorization). The sample sync adapter authenticator is also using appengine for the backend making things easier for you there. – andyandy May 23 '12 at 08:52
2

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 ;)

Moog
  • 10,193
  • 2
  • 40
  • 66
  • I've about figured it out own my own, but still have some things to iron out. I already had authentication with the google accounts setup in my app, so I really don't need to implement the getAuthToken and other methods in the AuthenticationService. I basically just want to use the syncadapter functionality...have any code you could share from the authentication service? how did you add the accounts in your app? – Patrick Jackson May 23 '12 at 09:48
  • All the code is in the SampleSyncAdapter example code that I linked in the answer. I stripped it down to basics (and broke it a few times) then bolted it into my code. One helpful hint though ... there's a tiny xml file that this thing needs which you will find in the sample project ... make sure you put it in your xml folder ... neraly went mad trying to solve that one ;) – Moog May 23 '12 at 10:01
  • This article may also be of use [connecting-the-dots-with-android-syncadapter](http://ericmiles.wordpress.com/2010/09/22/connecting-the-dots-with-android-syncadapter/) – Moog May 23 '12 at 18:21
  • also this http://stackoverflow.com/questions/6711382/google-appengine-custom-authentication – Moog May 23 '12 at 19:16
  • Another comprehensive post about creating a sync adapter, including a working sample app: http://udinic.wordpress.com/2013/07/24/write-your-own-android-sync-adapter/ – Udinic Jul 27 '13 at 21:02