5794b99f5b40e52162dec44236032837ce0ef215
[public/netxms.git] / android / src / console / src / org / netxms / ui / android / receivers / ConnectivityChangeIntentReceiver.java
1 package org.netxms.ui.android.receivers;
2
3 import org.netxms.ui.android.main.activities.HomeScreen;
4 import org.netxms.ui.android.service.ClientConnectorService;
5
6 import android.content.BroadcastReceiver;
7 import android.content.Context;
8 import android.content.Intent;
9 import android.content.SharedPreferences;
10 import android.net.ConnectivityManager;
11 import android.net.NetworkInfo;
12 import android.preference.PreferenceManager;
13
14 /**
15 * Intent receiver for connectivity change broadcast message
16 *
17 * @author Marco Incalcaterra (marco.incalcaterra@thinksoft.it)
18 *
19 */
20
21 public class ConnectivityChangeIntentReceiver extends BroadcastReceiver
22 {
23 @Override
24 public void onReceive(Context context, Intent intent)
25 {
26 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
27 if (!sp.getBoolean(HomeScreen.INTENTIONAL_EXIT_KEY, false))
28 if (intent.getExtras() != null)
29 {
30 if (!sp.getBoolean("global.scheduler.enable", false)) // Try to connect only when the scheduler is disabled
31 {
32 NetworkInfo ni = (NetworkInfo)intent.getExtras().get(ConnectivityManager.EXTRA_NETWORK_INFO);
33 if (ni != null && ni.getState() == NetworkInfo.State.CONNECTED)
34 {
35 Intent i = new Intent(context, ClientConnectorService.class);
36 i.setAction(ClientConnectorService.ACTION_FORCE_CONNECT);
37 context.startService(i);
38 }
39 }
40 if (intent.getExtras().getBoolean(ConnectivityManager.EXTRA_NO_CONNECTIVITY, Boolean.FALSE))
41 {
42 Intent i = new Intent(context, ClientConnectorService.class);
43 i.setAction(ClientConnectorService.ACTION_FORCE_DISCONNECT);
44 context.startService(i);
45 }
46 }
47 }
48 }