Broadcast Receiver to detect change in mobile network

半腔热情 提交于 2019-12-13 02:03:51

问题


I am looking for a way to make my Android app

do something every time there is a change in mobile network,

i.e. going from 2g to 3g, 4g to wifi etc.

All I can find for broadcast receivers are the ones that execute on loss or gain of network connection.


回答1:


Have you looked into using a PhoneStateListener? The LISTEN_DATA_CONNECTION_STATE and LISTEN_SERVICE_STATE flags look promising.



来源:https://stackoverflow.com/questions/5518719/broadcast-receiver-to-detect-change-in-mobile-network

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