This commit is contained in:
lixiaopeng
2020-08-20 09:51:29 +08:00
parent e1bab17d19
commit 7b3c69cb1a
2 changed files with 0 additions and 51 deletions

View File

@@ -42,14 +42,6 @@
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<receiver android:name=".receiver.NetWorkReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
</receiver>
</application>
</manifest>

View File

@@ -1,43 +0,0 @@
package com.mogo.module.tanlu.receiver
import android.Manifest
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.util.Log
import android.widget.Toast
import androidx.core.content.ContextCompat
import com.mogo.module.tanlu.util.NetworkUtil
/**
* @description 网络改变监听
*
* @author lixiaopeng
* @since 2019-10-17
*/
class NetWorkReceiver : BroadcastReceiver() {
private var isConnect = true
override fun onReceive(context: Context, intent: Intent?) {
if (ContextCompat.checkSelfPermission(
context,
Manifest.permission.ACCESS_NETWORK_STATE
) === PackageManager.PERMISSION_GRANTED
) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
isConnect = NetworkUtil.isConnected(context)
} else {
isConnect = NetworkUtil.isConnectedV21(context)
}
}
// if (!isConnect) {
// Toast.makeText(context, "网络已断开,请检查网络", Toast.LENGTH_SHORT).show()
// //TODO
//
// }
}
}