Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 没有网络时打开另一个活动_Android_Android Internet - Fatal编程技术网

Android 没有网络时打开另一个活动

Android 没有网络时打开另一个活动,android,android-internet,Android,Android Internet,我想打开另一个活动,如果没有网络,它将显示没有internet连接。我可以这样做吗?请帮忙 只需从类中添加代码,并使用if(isConnected()){startActivity(…)}或“不启动”或其他选项进行检查。。。 inline fun Context.withNetwork(isToNotify: Boolean = true, block: () -> Unit) { val connectivityManager = this.getSystemService(Co

我想打开另一个活动,如果没有网络,它将显示没有internet连接。我可以这样做吗?请帮忙

只需从类中添加代码,并使用
if(isConnected()){startActivity(…)}
或“不启动”或其他选项进行检查。。。
inline fun Context.withNetwork(isToNotify: Boolean = true, block: () -> Unit) {
    val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
    connectivityManager?.let {
        val netInfo = it.activeNetworkInfo
        val isConnected = netInfo != null && netInfo.isConnectedOrConnecting
        if (isToNotify && !isConnected){
            toast(R.string.message_no_network_message)
             //Use Here Intent For Another Activity

        }else{
            block()
        }
    }
}