|
|
|
@ -13,7 +13,11 @@ import android.telephony.SubscriptionInfo
|
|
|
|
|
import android.telephony.SubscriptionManager
|
|
|
|
|
import android.telephony.TelephonyManager
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import com.common.commonlib.CommonApplication
|
|
|
|
|
import com.common.commonlib.utils.LogUtils
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
object SimHelper {
|
|
|
|
@ -113,7 +117,8 @@ object SimHelper {
|
|
|
|
|
private var counter = 0
|
|
|
|
|
|
|
|
|
|
fun setNetStatus(status: Boolean) {
|
|
|
|
|
LogUtils.w("setNetStatus $status")
|
|
|
|
|
LogUtils.w("setNetStatus before=$isNetOK now =$status")
|
|
|
|
|
tryNoifyUser(status)
|
|
|
|
|
isNetOK = status
|
|
|
|
|
// UI刷新要慢
|
|
|
|
|
if (counter % 6 == 0) {
|
|
|
|
@ -133,6 +138,21 @@ object SimHelper {
|
|
|
|
|
counter++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 尝试通知用户
|
|
|
|
|
* @param status
|
|
|
|
|
*/
|
|
|
|
|
private fun tryNoifyUser(status: Boolean) {
|
|
|
|
|
if (isNetOK == status) {
|
|
|
|
|
// 状态无变化
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
val str = if (isNetOK && !status) "网络链接断开!" else "网络已连接!"
|
|
|
|
|
GlobalScope.launch(Dispatchers.Main) {
|
|
|
|
|
CommonApplication.getContext()?.showToast(str)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun isNetOk(): Boolean {
|
|
|
|
|
return isNetOK
|
|
|
|
|
}
|
|
|
|
|