我已在我的清单中声明android.net.conn.CONNECTIVITY_CHANGE
,以便在用户连接发生变化时通知我。
我正在为同一个活动收到多个广播。
当我打开移动连接并打开wifi时,检索到以下信息(intent.getExtras()
的打印)。
[ networkInfo => NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "HOME", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false; networkType => 1; inetCondition => 0; extraInfo => "HOME"; ]
[ networkInfo => NetworkInfo: type: mobile[UMTS], state: DISCONNECTED/DISCONNECTED, reason: dataDisabled, extra: web.network.de, roaming: true, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false; networkType => 0; otherNetwork => NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "HOME", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false; reason => dataDisabled; inetCondition => 0; extraInfo => web.network.de; ]
[ networkInfo => NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "HOME", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false; networkType => 1; inetCondition => 0; extraInfo => "HOME"; ]
是否可以首先接收断开连接事件而不是连接事件?
答案 0 :(得分:3)
据我所知,这是不可能的。 我认为这与Android在断开移动网络之前首先尝试通过WIFI连接(防止用户在连接失败时失去连接)这一事实有关。
无论如何,您始终可以保存收到的信息,然后根据需要进行处理。只需重新考虑您的方法,可能您不需要按顺序接收该信息。