自定义不同步与谷歌帐户(com.google)在某些三星设备的工作 [英] Custom sync not working with Google Account (com.google) on some Samsung devices

查看:249
本文介绍了自定义不同步与谷歌帐户(com.google)在某些三星设备的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个同步任务的方式与 BasicSyncAdapter例如的一样,除了用谷歌帐户,像这样的回答:

I implemented a sync task the same way as the BasicSyncAdapter example except with a Google account like in this answer:

http://stackoverflow.com/a/2972918/2072569

它适用于除三星SM-P600(Galaxy Note的2014年),采用Android 4.4.2和一些其他的三星平板电脑的allmost所有设备。

It works on allmost all devices except for the Samsung SM-P600 (Galaxy Note 2014) with Android 4.4.2 and some other Samsung tablets.

我在清单文件中的ContentProvider都有一个标签。这是根据这个帖子一些三星平板电脑的一些Android版本这个bug的原因。

My ContentProvider in the Manifest file has a label. This is the cause of this bug according to this post at some Android version of some Samsung tablets.

有三星将受阻任务同步到谷歌帐户,出于某种原因?

同步添加这样的:

removeAllSyncTasks();
ContentResolver.setIsSyncable(mAccount, CONTENT_AUTHORITY, 1);
ContentResolver.setSyncAutomatically(mAccount, CONTENT_AUTHORITY, true);
ContentResolver.addPeriodicSync(mAccount, CONTENT_AUTHORITY, Bundle.EMPTY, SYNC_FREQUENCY);

清单部分:

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


        <provider
            android:name=".data.provider.LevensContentProvider"
            android:authorities="@string/authority"
            android:label="@string/app_name_sync"
            android:exported="false"
            android:syncable="true" />

Syncadapter XML:

Syncadapter xml:

<?xml version="1.0" encoding="utf-8"?>
<sync-adapter
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentAuthority="@string/authority"
    android:accountType="com.google"
    android:userVisible="true"
    android:supportsUploading="true"
    android:allowParallelSyncs="false"
    android:isAlwaysSyncable="true"/> 

当我手动启动同步。该Syncservice还没有开始三星平板电脑(它适用于所有其他设备)。

When I manually start the sync. The Syncservice is also not starting at the Samsung tablets (it works on all other devices).

推荐答案

原来它一点关系都没有与三星/ OS版本...

It turns out it had nothing to do with Samsung / OS version...

我SyncHelper的构造是:

The constructor of my SyncHelper was:

 public SyncHelper(Context context, String accountName) {
        Account account = null;
        Account[] accounts = AccountManager.get(context).getAccounts();
        for (Account acc : accounts) {
            if(acc.name.equals(accountName)){
                account = acc;
            }
        }
        if(account == null){
            throw new InvalidParameterException("Account not found");
        }
        init(context, account);
    }

这不检查的帐户类型。有没有在列表类型com.evernote的帐户,这是用来同步和ofcourse将无法工作。

This does not check for the type of account. There was an account of type com.evernote in the list and this was used to sync and that ofcourse won't work.

添加到了解决这个问题:

Added this to solve it:

 public SyncHelper(Context context, String accountName) {
        Account account = null;
        Account[] accounts = AccountManager.get(context).getAccounts();
        for (Account acc : accounts) {
            if(acc.name.equals(accountName) && acc.type.equals(ACCOUNT_TYPE)){
                account = acc;
            }
        }
        if(account == null){
            throw new InvalidParameterException("Account not found");
        }
        init(context, account);
    }

现在我可以开始我撞的头靠在墙上...; - )

Now I can start bumping my head against the wall... ;-)

这篇关于自定义不同步与谷歌帐户(com.google)在某些三星设备的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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