KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I need to get the network from which device was disconnected. Now I use: NetworkInfo ni =intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); And check: ni.isConnected() if this returns false ni - is the network from which the device was disconnected. But ConnectivityManager.EXTRA_NETWORK_INFO is deprecated in API 14. Google says use getActiveNetworkInfo() to get network information. But getActiveNetworkInfo() always returns network with which the device is connected now ( isConnected() must return true)! How do I get the network info for the network the device disconnected from without using ConnectivityManager.EXTRA_NETWORK_INFO? Sertorio Noronha, when I use getActiveNetworkInfo() I only get the network to which I am connected now! But I need to get the network from which I was disconnected. ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo n1 = cm.getActiveNetworkInfo(); Log.d("tets", String.format("%s: %s", n1.getTypeName(), n1.isConnected())); When I disconnect from WI-FI and connect to 3G in log: mobile: true mobile: true When I disconnect from 3G and connect to WI-FI in log: WIFI: true WIFI: true WIFI: true getActiveNetworkInfo returns only the network connected to now, but does not return the network from which I was disconnected. If I use deprecated intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO) in log I see: When I disconnect from WI-FI and connect to 3G: WIFI: false mobile: true When I disconnect from 3G and connect to WI-FI: mobile: false WIFI: true But I do not want to use deprecated api. How to use modern api to get network from which
Tags (comma-separated)
Save Edits
Cancel