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 yet. What can I do to start a android.intent.action.BOOT_COMPLETEDand wait to have a network status?
for example I can have a android.intent.action.BOOT_COMPLETED but the phone has no internet connection, or I can have a android.intent.action.BOOT_COMPLETED and 5 seconds later a internet Access.
Get Network on android.intent.action.BOOT_COMPLETED
1.7k Views Asked by Alessio Crestani At
2
There are 2 best solutions below
2
On
You can always listen to multiple items on one receiver:
<receiver android:name=".ReceiverName" >
<intent-filter >
<action android:name="android.net.wifi.STATE_CHANGE" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
So after boot you just wait for connectivity change and do your stuff.
You could register a broadcast receiver listening on the android.net.conn.CONNECTIVITY_CHANGE action.
then check if you are connected like this:
source and more information: Broadcast receiver for checking internet connection in android app