所以我的BroadcastREceiver遇到了一个错误...接收器正在运行并检测到网络中的变化......一旦我添加了它可以看到的可见性......
罐装出去的地方是
中warning_message的可见性变化 val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = connectivityManager.activeNetworkInfo
if (networkInfo != null && networkInfo.detailedState == NetworkInfo.DetailedState.CONNECTED) {
Log.d("Network Connected","NC is connected")
MainActivity().warning_message.visibility = View.INVISIBLE
MainActivity().isConnected = true
} else if (networkInfo != null) {
val state = networkInfo.detailedState
Log.d("NetworkReceiver", state.name)
} else {
MainActivity().warning_message.visibility = View.VISIBLE
MainActivity().isConnected = false
Log.d("Network Connected","NC")
}
}
警告信息只是:
<FrameLayout
android:id="@+id/warning_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_toolbar">
主活动布局中的。
我收到的错误是: 处理:com.example.user.appname,PID:19972
java.lang.RuntimeException:接收广播Intent时出错{act = android.net.conn.CONNECTIVITY_CHANGE flg = 0x4000010(有额外的)} in com.example.user.appname.ConnectionReceiver@531d646
没有关于原因的具体错误消息。