簡體   English   中英

以編程方式啟用自動同步

[英]Enable auto sync programmatically

我想以編程方式在我的應用程序的帳戶設置中啟用自動同步。 我已經設置了 SyncAdapter,在清單中聲明了它,我添加了帳戶,在此操作之后我嘗試了:

ContentResolver.setSyncAutomatically(account, authority, true);
ContentResolver.setMasterSyncAutomatically(true);

但它不起作用。 SE上也有同樣的問題:

但是它們太舊了,在它們中我發現我需要使用ContentResolver.setMasterSyncAutomatically(true) ,但它不適用於我的 Android 7、Android 9。

未啟用自動同步

問題出在ContentResolver.setSyncAutomatically(account, authority, true);中的authority字符串參數中ContentResolver.setSyncAutomatically(account, authority, true); ,聯系人同步需要為"com.android.contacts"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM