Not receiving all network interfaces of an Android device

与世无争的帅哥 提交于 2019-12-20 07:10:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!