Skip to content Skip to sidebar Skip to footer

Get Network On Android.intent.action.boot_completed

I've an app that has a receiver of android.intent.action.BOOT_COMPLETED and start a private VPN. But when I receive a android.intent.action.BOOT_COMPLETED the network isn't ready y

Solution 1:

You could register a broadcast receiver listening on the android.net.conn.CONNECTIVITY_CHANGE action.

then check if you are connected like this:

publicbooleanisOnline(Context context) {

ConnectivityManagercm= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfonetInfo= cm.getActiveNetworkInfo();
//should check null because in air plan mode it will be nullreturn (netInfo != null && netInfo.isConnected());

}

source and more information: Broadcast receiver for checking internet connection in android app

Solution 2:

You can always listen to multiple items on one receiver:

<receiverandroid:name=".ReceiverName" ><intent-filter ><actionandroid:name="android.net.wifi.STATE_CHANGE" /><actionandroid:name="android.net.conn.CONNECTIVITY_CHANGE" /><actionandroid:name="android.intent.action.BOOT_COMPLETED" /></intent-filter></receiver>

So after boot you just wait for connectivity change and do your stuff.

Post a Comment for "Get Network On Android.intent.action.boot_completed"