android-connectivitymanager

How to handle network change between wifi and mobile data?

大城市里の小女人 提交于 2019-12-09 00:24:41
问题 I am building a VoIP app.During a VoIP call when user switches between WiFi to mobile data i have a problem handling the scenario. In my call screen activity I have registered for receiver which helps me get notified about the network change scenarios. This is the code which I am using for detecting change in networks in the onRecieve Method. conn_name is private class level variable holding previous connection name. ConnectivityManager connectivity_mgr = ((ConnectivityManager) context

Difference between registerDefaultNetworkCallback and registerNetworkCallback

只愿长相守 提交于 2019-12-05 02:35:13
I came across registerDefaultNetworkCallback and registerNetworkCallback while updating my Android app for API 28. Having reviewed the documentation, I cannot find the difference between registering a network callback and registering a default network callback . When will one use which? Thanks in advance :) As far as I understood, the difference between registerDefaultNetworkCallback and registerNetworkCallback it's only based on customisation. registerDefaultNetworkCallback works (surprisingly) as a default network listener, while registerNetworkCallback it's more configurable. For example:

Get Android DhcpInfo connected via Ethernet

本小妞迷上赌 提交于 2019-12-03 03:39:16
How to get DhcpInfo() (gateway ip, netmask, dns, etc) of android device connected via Ethernet? I know how to get it if device connected via Wifi and using ACCESS_WIFI_STATE permission: WifiManager wifi = (WifiManager) context.getSystemService(Service.WIFI_SERVICE); DhcpInfo dhcp = wifi.getDhcpInfo(); But I still not found the way to get it if device connected via ethernet... Thanks In your AndroidManifest.xml file <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> Your code: ConnectivityManager

How to handle network change between wifi and mobile data?

大城市里の小女人 提交于 2019-11-30 17:11:31
I am building a VoIP app.During a VoIP call when user switches between WiFi to mobile data i have a problem handling the scenario. In my call screen activity I have registered for receiver which helps me get notified about the network change scenarios. This is the code which I am using for detecting change in networks in the onRecieve Method. conn_name is private class level variable holding previous connection name. ConnectivityManager connectivity_mgr = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)); NetworkInfo net_info = connectivity_mgr.getActiveNetworkInfo

Check internet connection in android (not network connection)

旧街凉风 提交于 2019-11-29 16:03:03
I have a problem with checking internet connection in android at runtime. I use some different methods to check internet connection but i don't know which one is better . because each of them have some problems . Method 1 check internet connection by pinging Google : Runtime runtime = Runtime.getRuntime(); try { Process mIpAddressProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8"); int mExitValue = mIpAddressProcess.waitFor(); return mExitValue == 0; } catch (InterruptedException | IOException ignore) { ignore.printStackTrace(); } Method 2 check internet connection by ConnectivityManager :

ConnectivityManager getNetworkInfo(int) deprecated

喜欢而已 提交于 2019-11-26 23:45:14
Using compileSdkVersion 23 , however trying to support as far back as 9. getNetworkInfo(int) was deprecated in 23. The suggestion was to use getAllNetworks() and getNetworkInfo(Network) instead. However both of these require minimum of API 21. Is there a class that we can use in the support package that can assist with this? I know that a solution was proposed before , however the challenge of my minimum API requirements of 9 poses a problem. Cheese Bread You can use: getActiveNetworkInfo(); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);