mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-11 01:46:24 +00:00
Event: connectivity changed: prepare a handler when data conn become available
This commit is contained in:
parent
455f860902
commit
6292011e9b
@ -13,6 +13,7 @@
|
||||
<!-- For SMS Broadcaster -->
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<!-- For syncer -->
|
||||
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
|
||||
|
@ -1,18 +1,34 @@
|
||||
package fr.unix_experience.owncloud_sms.broadcast_receivers;
|
||||
|
||||
import fr.unix_experience.owncloud_sms.notifications.OCSMSNotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class ConnectivityChanged extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG,"ConnectivityChanged.onReceive");
|
||||
(new OCSMSNotificationManager(context)).setDebugMsg("ConnectivityChanged");
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// Check the connectivity
|
||||
final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
final android.net.NetworkInfo niWiFi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
final android.net.NetworkInfo niMobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||
|
||||
// If data is available and previous dataConnectionState was false, then we need to sync
|
||||
if ((niWiFi.isAvailable() || niMobile.isAvailable()) && dataConnectionAvailable == false) {
|
||||
dataConnectionAvailable = true;
|
||||
Log.d(TAG,"ConnectivityChanged.onReceive, data conn available");
|
||||
// @TODO: check if last message is last synced msg (shared preference)
|
||||
}
|
||||
// No data available and previous dataConnectionState was true
|
||||
else if (dataConnectionAvailable == true && !niWiFi.isAvailable() && !niMobile.isAvailable()) {
|
||||
dataConnectionAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean dataConnectionAvailable = false;
|
||||
|
||||
private static final String TAG = ConnectivityChanged.class.getSimpleName();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user