-
Notifications
You must be signed in to change notification settings - Fork 1
InternetService
Shailendra Lodhi edited this page Dec 14, 2021
·
1 revision
Step 1 :
First Create A Kotlin Class File!
Step 2 :
Add below Code in menifest file
<receiver android:name = ".util.InternetService"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"
tools:ignore="BatteryLife" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
</receiver>
Also Add Internet Permission -
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Step 3 :
Implement InternetService.ConnectivityReceiverListener
Register Broad Cast Receiver -
private val connectionListener : InternetService = InternetService()
override fun onResume() {
super.onResume()
registerReceiver( connectionListener, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
InternetService.connectivityReceiverListener = this
}
override fun onStop() {
super.onStop()
unregisterReceiver( connectionListener )
}
Hello, I'm Shailendra Lodhi from Bhopal, India. I do android development as freelancer. I hope you like this repository. You can follow up my Instagram - ( @Wackycodes) page to learn more in android and java. To connect with me - Click Here