SyncAdapter only in WIFI

I want to run my SyncAdapteronly on Wi-Fi. In the beginning, onPerformSyncI can check if Wi-Fi is present. If this is not the case, I want to postpone it until WIFI is available.

I know syncresult.delayUntil, but that means the sync adapter is useless to call every x minutes, although Wi-Fi can be turned off, for example, all day. Also, from what I read, delayUntildoes not apply if you use triggerSyncdirectly.

What is the best approach here? Applications like Evernote seem to have this ability to sync only in WIFI.

+5
source share
1 answer

Do not set periodic start SyncAdapter.

BroadcastReceiver :

<intent-filter>
<action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
<action android:name="android.net.wifi.STATE_CHANGE"/>
</intent-filter>

BroadcastReceiver , WiFi, , :

ContentResolver.requestSync(<Your account, <Your authority>, extras);

Android SyncAdapter.

+2

All Articles