Merge "Display all link IP addresses, on different lines"
This commit is contained in:
committed by
Android (Google) Code Review
commit
b75f10305d
@@ -330,7 +330,7 @@ public class Utils {
|
|||||||
/**
|
/**
|
||||||
* Returns the WIFI IP Addresses, if any, taking into account IPv4 and IPv6 style addresses.
|
* Returns the WIFI IP Addresses, if any, taking into account IPv4 and IPv6 style addresses.
|
||||||
* @param context the application context
|
* @param context the application context
|
||||||
* @return the formatted and comma-separated IP addresses, or null if none.
|
* @return the formatted and newline-separated IP addresses, or null if none.
|
||||||
*/
|
*/
|
||||||
public static String getWifiIpAddresses(Context context) {
|
public static String getWifiIpAddresses(Context context) {
|
||||||
ConnectivityManager cm = (ConnectivityManager)
|
ConnectivityManager cm = (ConnectivityManager)
|
||||||
@@ -343,7 +343,7 @@ public class Utils {
|
|||||||
* Returns the default link's IP addresses, if any, taking into account IPv4 and IPv6 style
|
* Returns the default link's IP addresses, if any, taking into account IPv4 and IPv6 style
|
||||||
* addresses.
|
* addresses.
|
||||||
* @param context the application context
|
* @param context the application context
|
||||||
* @return the formatted and comma-separated IP addresses, or null if none.
|
* @return the formatted and newline-separated IP addresses, or null if none.
|
||||||
*/
|
*/
|
||||||
public static String getDefaultIpAddresses(Context context) {
|
public static String getDefaultIpAddresses(Context context) {
|
||||||
ConnectivityManager cm = (ConnectivityManager)
|
ConnectivityManager cm = (ConnectivityManager)
|
||||||
@@ -354,14 +354,14 @@ public class Utils {
|
|||||||
|
|
||||||
private static String formatIpAddresses(LinkProperties prop) {
|
private static String formatIpAddresses(LinkProperties prop) {
|
||||||
if (prop == null) return null;
|
if (prop == null) return null;
|
||||||
Iterator<InetAddress> iter = prop.getAddresses().iterator();
|
Iterator<InetAddress> iter = prop.getAllAddresses().iterator();
|
||||||
// If there are no entries, return null
|
// If there are no entries, return null
|
||||||
if (!iter.hasNext()) return null;
|
if (!iter.hasNext()) return null;
|
||||||
// Concatenate all available addresses, comma separated
|
// Concatenate all available addresses, comma separated
|
||||||
String addresses = "";
|
String addresses = "";
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
addresses += iter.next().getHostAddress();
|
addresses += iter.next().getHostAddress();
|
||||||
if (iter.hasNext()) addresses += ", ";
|
if (iter.hasNext()) addresses += "\n";
|
||||||
}
|
}
|
||||||
return addresses;
|
return addresses;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user