Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom sync not working with Google Account (com.google) on some Samsung devices

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

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

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.

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.

Has Samsung blocked adding sync tasks to a Google account for some reason?

The sync is added like this:

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

Manifest part:

        <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:

<?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"/> 

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

like image 798
Roel Avatar asked Jul 08 '15 11:07

Roel


People also ask

Why is my Google keep not syncing across devices?

Turn Android sync settings on On your Android phone or tablet, tap Settings . Select the Google Account the note has been shared with. On the "Sync" screen, find and turn on Keep.

Why won't my Google Account Sync on my phone?

One of the first things that trigger the "Sync is currently experiencing problem" notification on Android is a poor internet connection. Your phone needs an active internet connection to sync information across your accounts. So, synchronization won't work if your internet is down.


1 Answers

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

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);
    }

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... ;-)

like image 195
Roel Avatar answered Sep 16 '22 17:09

Roel