问题
I'm trying to query network changes made to some specific network interfaces.
I'm doing it by registering a BroadcastReceiver
like this:
<receiver android:name="com.my.app.ReceiverNetworkInterfaceChange">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
And when there is a change, it triggers a method which query the interfaces using this call:
final List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
I've been testing it by turning airplane mode on and off. The receiver detects the change and its triggered.
The problem is that after changing the airplane mode status, not all interfaces are received from the getNetworkInterfaces()
call. If I call the method directly without involving the airplane mode, the list of interfaces contains an interface called "ppp0", but after turning airplane mode on and off, the call does not return that "ppp0" interface on the list so I can't query it...
Why is this happening for this specific interface?
回答1:
What I eventually did was checking the interfaces every minute instead of using the BroadcastReceiver
. This way, the interface eventually got back to the interfaces list after a while.
来源:https://stackoverflow.com/questions/45607188/not-receiving-all-network-interfaces-of-an-android-device