简体   繁体   English

在模拟器上调用了onPerformSync,但没有在物理设备上调用

[英]onPerformSync called on emulator but not physical device

I've built an Account sync adapter to show contacts from the app in local contact book. 我已经建立了一个帐户同步适配器,以在本地通讯录中显示来自该应用程序的联系人。

There is a fake authonticator that provides account. 有一个提供帐户的伪造身份验证器。 Also account is syncable 帐户也可以同步

    ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
    ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);

This account is displayed in all accounts on the device: 该帐户将显示在设备上的所有帐户中:

在此处输入图片说明

I've tried to trigger onPerformSync by system - from settings in menu press 'sync now' and programatically: 我试图通过系统触发onPerformSync-从菜单中的设置按“立即同步”并以编程方式触发:

public static void triggerRefresh() {
    Bundle b = new Bundle();
    b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    Account account = AccountAuthenticatorService.GetAccount();

    if (ContentResolver.isSyncPending(account, ContactsContract.AUTHORITY)  ||
            ContentResolver.isSyncActive(account, ContactsContract.AUTHORITY)) {
        ContentResolver.cancelSync(account, ContactsContract.AUTHORITY);
    }

    ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
    ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
    ContentResolver.requestSync(
            account, // Sync account
            ContactsContract.AUTHORITY,authority
            b);
}

It works fine on emulator, but on several devices (sony, samsung) it not triggered at all (I've tried to log smth in onPerformSync method but never see this log). 它在模拟器上可以正常工作,但是在几个设备(索尼,三星)上却根本不会触发(我试图在onPerformSync方法中记录某事,但从未看到此日志)。

I've tried to find such problem, but nothing helps, I can't make onPerformSync force to be called. 我试图找到这样的问题,但没有任何帮助,我无法强制调用onPerformSync。

What the main difference between emulator and device according to syncAdapter? 根据syncAdapter,模拟器和设备之间的主要区别是什么?

Finally I've found the reason of this issue: 最后,我找到了此问题的原因:

onPerformSync method will never be called until you don't have internet connection. 在没有互联网连接之前,永远不会调用onPerformSync方法。 On several devices and emulators there was an internet connection but on others you can't trigger this method. 在多个设备和仿真器上都有互联网连接,但是在其他设备和仿真器上,您无法触发此方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM