0

On Activity start my app is checking for ANY possible network providers, and if there is no network available it shuts down and stops executing code, so user can do nothing till user reopen app.

I want to make it so that the connection detector runs all the time. If user got to app without internet connection, then my app stops running; I want my app to periodically scan code so my app will resume after user connects to any network WITHOUT LEAVING MY APP. Thanks in advance.

sjobe
  • 2,817
  • 3
  • 24
  • 32
  • possible duplicate of [How can i call Wi-Fi settings screen from my application using Android](http://stackoverflow.com/questions/2318310/how-can-i-call-wi-fi-settings-screen-from-my-application-using-android) – WOUNDEDStevenJones Sep 24 '14 at 19:51

1 Answers1

0

This is simple.

1) read the docs http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html

2) implement Broadcast Receiver like

public class UnifiedReceiver extends BroadcastReceiver {

    private static final String TAG = UnifiedReceiver.class.getSimpleName();
    private static final String ACTION_CONNECTIVITY_CHANGE = "android.net.conn.CONNECTIVITY_CHANGE";

    /**
     * the constructor
     */
    public UnifiedReceiver ( ) {
        super();
    }

    /* (non-Javadoc)
     * @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
     */
    @Override
    public void onReceive ( Context context, Intent intent ) {
        final String TAG2 = "onReceive";
        Log.d(TAG, "entering "+TAG2+"()");

        if (intent.getAction().equals(ACTION_CONNECTIVITY_CHANGE)) {
            Log.d(TAG, TAG2+": '"+ACTION_CONNECTIVITY_CHANGE+"' received.");
            // do something useful
        }
    }

}
Andrey Kopeyko
  • 1,556
  • 15
  • 14