- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
当我将联系人添加到我的电话簿时,同步适配器的 onPerformSync() 方法被触发。但我无法弄清楚如何在该方法中检索新添加的联系方式。请帮助我提供一些指导和代码 fragment 。感谢您的帮助。
最佳答案
您帐户的联系人存储在 RawContacts
中 table 。数据(例如电话号码、电子邮件地址)存储在 Data 中表(RAW_CONTACT_ID
指向 RawContacts
表中该联系人的行 _ID
)。
要检测新联系人,您的同步适配器需要维护 RawContacts
中的 SOURCE_ID
字段表。
文档说明了 SOURCE_ID
(在顶部的字段列中):
String that uniquely identifies this row to its source account. Typically it is set at the time the raw contact is inserted and never changed afterwards. The one notable exception is a new raw contact: it will have an account name and type (and possibly a data set), but no source id. This indicates to the sync adapter that a new contact needs to be created server-side and its ID stored in the corresponding SOURCE_ID field on the phone.
因此您的同步适配器应该查找属于您的帐户类型且具有空 SOURCE_ID
的联系人。同步联系人后,它必须将 SOURCE_ID
设置为标识新联系人的(非空)值。
当您从服务器同步新联系人时,您需要在 Android 上插入新联系人时设置 SOURCE_ID
。如果不这样做,将导致重复(因为联系人将在下一次同步时作为新联系人同步回服务器)。
关于android - 如何在Sync Adapter onPerformSync 方法中访问新添加的联系人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36518226/
我在 AbstractThreadedSyncAdapter 的 onPerformSync 方法中进行网络操作。我想知道当我的应用程序在前台、后台和死机中运行时,这些操作是否默认在单独的线程上运行。
我的应用程序有一个按照 Android developer site 显示的结构创建的同步适配器. onPerformSync() 方法从互联网获取数据并使用批量插入将其插入数据库: Vector c
我为我的应用构建了一个 SyncAdapter,以便我可以使用 Google Cloud Messaging 触发数据库与服务器的同步。我实际上使用 Volley 进行网络调用并同步数据,但从我读到的
我正在使用 AbstractThreadedSyncAdapter 将我的 Android 手机中的一些数据与服务器同步。当用户使用手机的应用程序登录时,我会执行第一次同步,以便用户在开始使用我的
我有一个 SyncAdapter 类,它连接到 MQTT 代理并为服务器发布负载以接收负载。但是,似乎即使调用了 onPerformSync() 方法,也无法访问互联网。我认为使用 SyncAdapt
除了一件事,我的 syncadapter 运行良好。用户安装应用程序后,我的应用程序会同步两次。稍后,如果我在“设置”中手动同步它,它只会按预期同步一次。这只是发生这种情况的应用程序的第一次运行。 这
我关注这个标题Why does ContentResolver.requestSync not trigger a sync?但同步方法不会出现在设置屏幕的帐户和同步中。我认为 onPerformSy
正在尝试为我的内容提供者设置一个同步适配器/服务。内容提供者工作正常,能够毫无问题地存储数据。 我有一个向我的内容解析器注册的内容观察器,并且在数据更改后调用 onChange 方法。 但是,在我调用
我正在尝试实现同步适配器,我已经关注了This guide. 但是 onPerformSync() 在 ContentResolver.requestSync() 调用之后没有被触发。 我也尝试了一些
我正在创建一个 Android 应用程序,它向用户提供一个按钮来刷新数据库,以便本地数据和服务器上的数据保持同步。 我已经创建了帐户验证器、内容提供器并通过服务绑定(bind)了它们。 Content
我已经使用 Android 设置了一个 SyncAdapter sample project 、Steele 的两部分教程(1 和 2)和 Google I/O 2010 关于 REST 应用程序的演
当我将联系人添加到我的电话簿时,同步适配器的 onPerformSync() 方法被触发。但我无法弄清楚如何在该方法中检索新添加的联系方式。请帮助我提供一些指导和代码 fragment 。感谢您的帮助
我正在通过 SyncAdapter onPerformSync 发送几个改造调用,并且我试图通过通过 try/catch sleep 语句发送出去来调节 http 调用。但是,这会阻塞 UI,并且只有
你们能不能帮我一下。我一直在尝试在 onPerformSyn 中运行 yelp api。我怎么可能这样做。?我收到以下错误。 “没有空的构造函数”我正在使用这个 post尝试创建构造函数,但它对我不起
我使用 SyncAdapter 将我的数据与服务器同步。一切正常,但我很难向 SyncAdapter 发送额外内容。 在我的 ContentObserver 中,我使用以下代码向 SyncAdapte
我收到了大量来自用户的错误报告,这些错误报告来自强制关闭对话框,内容如下: java.lang.ExceptionInInitializerError at com.MyRequest.execute
我正在尝试使用 AbstractThreadedSyncAdapter 将我的本地数据库与我的服务器同步。我已经按照找到的指南进行操作,但无法正常工作。适用于 Android 2.2。 我的身份验证器
我是一名优秀的程序员,十分优秀!