问题描述
我使用了谷歌的android开发人员文档( http://developer.android.com/training/sync-Adapters )创建同步系统.
我的应用现在在帐户下有一个条目.当我点击此条目,我看到我已配置的同步适配器.除了未选中框中,一切都看起来正常,它说"同步已关闭".
我已经oogled和stackoverflowed,似乎有一种方法可以启用同步,如这里所述: https://stackoverflow.com/a/5279191/127434 .该链接的答案表示要调用ContentResolver.setSyncAutomatically(account, authority, true).
但是,Google的文档( http://developer.android.com/trainn/sync-adatters/running-sync-adapter.html#runbynetwork )说:当网络连接可用时,Android系统会发出a 消息每隔几秒钟保持打开设备的TCP/IP连接. 此消息还转到每个应用程序的ContentResolver.通过呼叫 setsyncautomicaloal(),只要使用时可以运行SYNC适配器 ContentResolver接收消息.
但我不想每隔几秒钟同步一次. (我想使用ContentResolver.addPeriodicSync,安排一小时几次同步.)
所以如何为我的适配器进行同步而不每隔几秒钟同步同步?
推荐答案
您应该添加 contentResolver.setmastersyCautomic(真实);到你的代码.如果没有这种情况,将忽略SeterynCautomay.
问题描述
I have used Google's Android developer documentation (http://developer.android.com/training/sync-adapters) to create a syncing system.
My app now has an entry in Android Settings under Accounts. When I tap this entry, I see the sync adaptor I have configured. Everything looks ok except that the box is unchecked and it says "Sync is OFF".
I have Googled and Stackoverflowed and there seems to be one way to enable sync, as explained here: https://stackoverflow.com/a/5279191/127434. The answer at that link says to call ContentResolver.setSyncAutomatically(account, authority, true).
However, Google's docs (http://developer.android.com/training/sync-adapters/running-sync-adapter.html#RunByNetwork) say:
When a network connection is available, the Android system sends out a message every few seconds to keep the device's TCP/IP connection open. This message also goes to the ContentResolver of each app. By calling setSyncAutomatically(), you can run the sync adapter whenever the ContentResolver receives the message.
But I don't want to sync every few seconds. (I'd like to use ContentResolver.addPeriodicSync to schedule a sync a few times an hour.)
So how can I enable syncing for my adaptor without having it sync every few seconds?
推荐答案
You should add ContentResolver.setMasterSyncAutomatically(true); to your code. Without this the setSyncAutomatically will be ignored.
Read the documentation [here] (http://developer.android.com/reference/android/content/ContentResolver.html#setMasterSyncAutomatically(boolean))