Yonatan Nir Yonatan Nir - 1 year ago 66
Android Question

Not receiving all network interfaces of an Android device

I'm trying to query network changes made to some specific network interfaces.

I'm doing it by registering a

like this:

<receiver android:name="com.my.app.ReceiverNetworkInterfaceChange">
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />

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
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download