Android的SyncAdapter使用谷歌账户 [英] Android SyncAdapter using a google account

查看:148
本文介绍了Android的SyncAdapter使用谷歌账户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了SyncAdapter,需要一个com.google帐户并进行同步与应用程序引擎Web服务。与开发工具的同步测试仪(仿真器)测试此,同步似乎工作得很好。

I have written a SyncAdapter that takes a "com.google" account and performs a sync with an appengine web service. Testing this with the dev tools sync tester (on the emulator), this sync appears to work just fine.

现在的问题是,它不是同步默认情况下。而将账户中的账户与同步显示我的谷歌帐户是空白 - 因为如果有可用的同步服务

The problem is, it's not syncing by default. And going to the account in "accounts & sync" shows my google account to be blank - as if there's no sync services available.

我怀疑,为了获得显示在账户与同步我的同步菜单,我需要实现我自己的AccountAuthenticator,将做同样的事情,我已经presume谷歌的AccountAuthenticator绝做。这不是一个令人兴奋的工作,它似乎非常必要。所以:

I suspect that in order to get my sync shown in the "accounts & sync" menu, I'd need to implement my own AccountAuthenticator that would do exactly the same thing as what I presume google's AccountAuthenticator must already do. This is not an exciting job, and it seems very unnecessary. So:

  • 有没有办法添加一个条目的账户与同步使用我的SyncAdapter而是依靠一个谷歌帐户菜单?或者增加一个子菜单到Google帐户,使我的应用程序引擎服务的同步?

如果不是,

  • 有没有一种方法,我可以重新使用谷歌的AccountAuthenticator从AccountAuthenticator在我写的?

推荐答案

因此​​,原来你可以有一个使用com.google帐户syncAdapter,但是这需要你写一个匹配的ContentProvider。例如,在AndroidManifest.xml中:

So it turns out you can have a syncAdapter that uses a "com.google" account, but this requires you write a matching ContentProvider. For example, in AndroidManifest.xml:

<service android:name=".sync.SyncAdapterService" android:exported="true" android:process=":contacts">
  <intent-filter>
    <action android:name="android.content.SyncAdapter" />
  </intent-filter>
  <meta-data android:name="android.content.SyncAdapter" android:resource="@xml/syncadapter" />
</service>

和在syncadapter.xml:

and in syncadapter.xml:

<?xml version="1.0" encoding="utf-8"?>
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentAuthority="net.gfxmonk.android.pagefeed"
    android:accountType="com.google"
    android:supportsUploading="false"
    android:userVisible="true"
/>

您那么的必须的有权威net.gfxmonk.android.pagefeedContentProvider的,以便为Android与您的应用程序的同步操作相关联。一旦你有了这个(它甚至不需要做任何有意义的,只是存在的话),你的程序可以显示里面的账户与同步设置面板 - 您所选择的谷歌帐户中

You then must have a ContentProvider with authority "net.gfxmonk.android.pagefeed" in order for android to associate that sync action with your application. Once you have this (it doesn't even need to do anything meaningful, just exist), your program can appear inside the "accounts & Sync" setting panel - within your chosen google account.

作为一个额外的作品,你可能需要调用:

As an additional piece of work, you may need to call:

ContentResolver.setIsSyncable(account, "net.gfxmonk.android.pagefeed", 1)

与账号,只要你想用你的同步凭据的帐户对象。

with account as the Account object you want to use for your sync credentials.

这篇关于Android的SyncAdapter使用谷歌账户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆