Open the application when connected to Wi-Fi

How to open the application when a user enters a zone with wi-fi? Is it possible? Suppose my application is in onPause () state (means the My Device home screen). Now that the device is connected to Wi-Fi. it will automatically open my application.

+5
source share
3 answers

Try to add a broadcast receiver and listen to network changes, when wi-fi connects, start your activity. Something like this solution

public class ConnectivityReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

                ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
                NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
                if (((null != wifi)&&(wifi.isAvailable())) || ((null != mobile)&&(mobile.isAvailable()))){
                    Intent uplIntent = new Intent(context, YourActivity.class);
                    uplIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(uplIntent);
                }

    }
}

And add to the manifest

    <receiver android:name=".receiver.ConnectivityReceiver">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        </intent-filter>
    </receiver>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+5
source

What I can imagine is rewriting a method onPause()like this:

@Override
public void onPause() {
    String conn_context = Context.WIFI_SERVICE;
    final WifiManager wifi = (WifiManager) getSystemService(conn_context);
    if (wifi.isWifiEnabled())
    {
      super.onResume();
    }
    else
    {
      super.onPause(); 
    }
}

onPause.

0

Perhaps the Tasker app from the Play Store is possible (but not free). Or you can create a Service ( http://developer.android.com/guide/components/services.html ) that will contain the code described in other answers, and then run the application (Activity) when wifi is available.

0
source

All Articles