문제

So I have a SyncAdapter implemented in my app. I use the user's existing Google account since I am syncing with Google Tasks. In the app, users have to go to preferences, enable sync and select an account. At this point I try to fetch an authToken which will create a pop-up asking the user to authorize my app to use their selected Google account.

enter image description here

This all works great if the user has never installed my app before. But, assume now that the user un-installs the app and re-installs it at a later time. When they open up the app, the settings will be unchecked of course. But what they'll find is that the app syncs with their previously selected Google account anyway!

The reason is that the SyncAdapter is toggled to sync by default. E.g. this is the view in the Accounts & Sync screen after install before any changes have been made:

It is checked to sync by default. On first install this doesn't matter because my app is not approved to access their Google account yet. But on re-install, it does matter. So my question is: What do I need add/change/remove to make it unchecked by default?

My syncadapter.xml is as follows:

<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
    android:contentAuthority="com.nononsenseapps.NotePad"
    android:accountType="com.google"
    android:supportsUploading="true"
    android:userVisible="true" />

And in the manifest:

<service
    android:name=".sync.SyncService"
    android:exported="true" >
    <intent-filter>
        <action android:name="android.content.SyncAdapter" />
    </intent-filter>

    <meta-data
        android:name="android.content.SyncAdapter"
        android:resource="@xml/syncadapter" />
</service>

I do not make any calls in the Java code concerning sync until the user selects an account in settings.

도움이 되었습니까?

해결책

You can store a SharedPreference and check it on SyncService start. If false, stop the service and don't do anything.

Remember to .apply() or .commit() your new shared preference value when you set it from the user config to enable sync.

다른 팁

ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, false);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top