T
- The PeriodicReplicationService
component triggered by this
BroadcastReceiver
public abstract class WifiPeriodicReplicationReceiver<T extends PeriodicReplicationService> extends PeriodicReplicationReceiver
This class extends PeriodicReplicationReceiver
so that periodic replications are only
started when the device is connected to a WiFi network and are stopped when the device
disconnects from a WiFi network.
This uses the standard Android broadcasts to detect connectivity change and then trigger the periodic replications.
To use this, you should create a subclass of this class whose default constructor calls
the constructor of this class passing in the name of the concrete
PeriodicReplicationService
you are using - e.g.:
public class MyWifiPeriodicReplicationReceiver extends WifiPeriodicReplicationReceiver<MyReplicationService> { public MyWifiPeriodicReplicationReceiver() { super(MyReplicationService.class); } }
You should then add your subclass to the AndroidManifest.xml
as a child of the application
tag and add IntentFilter
s as follows:
<receiver android:name=".MyWifiPeriodicReplicationReceiver" android:exported="false"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> <action android:name="com.cloudant.sync.replication.PeriodicReplicationReceiver.Alarm" /> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
You must then add the following permissions to your AndroidManifest.xml
file:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Modifier and Type | Method and Description |
---|---|
static boolean |
isConnectedToWifi(android.content.Context context) |
void |
onReceive(android.content.Context context,
android.content.Intent intent) |
completeWakefulIntent, startWakefulService
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, goAsync, isInitialStickyBroadcast, isOrderedBroadcast, peekService, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtras
public void onReceive(android.content.Context context, android.content.Intent intent)
onReceive
in class PeriodicReplicationReceiver
public static boolean isConnectedToWifi(android.content.Context context)