mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-09 13:50:57 +00:00
Shortened interval to resend event when connectivity was missing, Added the ConnectivityChangedReceiver that listens for OS broadcasts about connectivity when the connectivity was lost
This commit is contained in:
1 parent
b53107d97b
commit
461e588cca
3 files changed
+60
-4
No files matched your search
@@ -66,8 +66,11 @@
|
||||
<action android:name="com.sap.sailing.racecommittee.app.action.sendEvent" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
|
||||
<receiver android:name=".receiver.ConnectivityChangedReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.sap.sailing.racecommittee.app.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
|
||||
public class ConnectivityChangedReceiver extends BroadcastReceiver {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
|
||||
*/
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
NetworkInfo networkInfo = (NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
|
||||
if (!networkInfo.isConnected())
|
||||
return;
|
||||
Intent sendSavedIntent = new Intent(context.getResources().getString(R.string.intentActionSendSavedIntents));
|
||||
context.startService(sendSavedIntent);
|
||||
|
||||
disable(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* disables the Connectivity Changed Receiver as there is currently connectivity
|
||||
* @param context the context to work on
|
||||
*/
|
||||
public static void disable(Context context) {
|
||||
ComponentName receiver = new ComponentName(context, ConnectivityChangedReceiver.class);
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
packageManager.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
/**
|
||||
* enables the Connectivity Changed Receiver to listen on connectivity changes as there is currently no connectivity
|
||||
* @param context the context to work on
|
||||
*/
|
||||
public static void enable(Context context) {
|
||||
ComponentName receiver = new ComponentName(context, ConnectivityChangedReceiver.class);
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
packageManager.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
}
|
||||
+3
-2
@@ -21,6 +21,7 @@ import com.sap.sailing.racecommittee.app.data.DataManager;
|
||||
import com.sap.sailing.racecommittee.app.data.ReadonlyDataManager;
|
||||
import com.sap.sailing.racecommittee.app.domain.ManagedRace;
|
||||
import com.sap.sailing.racecommittee.app.logging.ExLog;
|
||||
import com.sap.sailing.racecommittee.app.receiver.ConnectivityChangedReceiver;
|
||||
import com.sap.sailing.racecommittee.app.services.sending.EventSenderTask.EventSendingListener;
|
||||
|
||||
/*
|
||||
@@ -145,7 +146,7 @@ public class EventSendingService extends Service implements EventSendingListener
|
||||
private void handleSendEvents(Intent intent) {
|
||||
if (!isConnected()) {
|
||||
persistenceManager.persistIntent(intent);
|
||||
//ConnectivityChangedReceiver.enable(this);
|
||||
ConnectivityChangedReceiver.enable(this);
|
||||
} else {
|
||||
sendEvent(intent);
|
||||
}
|
||||
@@ -181,7 +182,7 @@ public class EventSendingService extends Service implements EventSendingListener
|
||||
persistenceManager.persistIntent(intent);
|
||||
if (!isHandlerSet) {
|
||||
SendDelayedEventsCaller delayedCaller = new SendDelayedEventsCaller(this);
|
||||
handler.postDelayed(delayedCaller, 1000 * 60 * 1);
|
||||
handler.postDelayed(delayedCaller, 1000 * 30); //after 30 sec, try the sending again
|
||||
isHandlerSet = true;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user