@Test public void testFormatIpAddress() throws UnknownHostException { for (long i = Integer.MIN_VALUE; i <= Integer.MAX_VALUE; i += 98273) { String ip = WifiStateChangeService.formatIpAddress((int) i); InetAddress.getByName(ip); } InetAddress.getByName(WifiStateChangeService.formatIpAddress(Integer.MAX_VALUE)); InetAddress.getByName(WifiStateChangeService.formatIpAddress(Integer.MIN_VALUE)); InetAddress.getByName(WifiStateChangeService.formatIpAddress(0)); }
static String formatIpAddress(int ipAddress) { if (ipAddress == 0) { return null; } return String.format(Locale.ENGLISH, "%d.%d.%d.%d", ipAddress & 0xff, ipAddress >> 8 & 0xff, ipAddress >> 16 & 0xff, ipAddress >> 24 & 0xff); }
WifiStateChangeService extends IntentService { static String formatIpAddress(int ipAddress) { if (ipAddress == 0) { return null; } return String.format(Locale.ENGLISH, "%d.%d.%d.%d", ipAddress & 0xff, ipAddress >> 8 & 0xff, ipAddress >> 16 & 0xff, ipAddress >> 24 & 0xff); } }
WifiStateChangeService extends IntentService { static String formatIpAddress(int ipAddress) { if (ipAddress == 0) { return null; } return String.format(Locale.ENGLISH, "%d.%d.%d.%d", ipAddress & 0xff, ipAddress >> 8 & 0xff, ipAddress >> 16 & 0xff, ipAddress >> 24 & 0xff); } WifiStateChangeService(); }
WifiStateChangeService extends IntentService { static String formatIpAddress(int ipAddress) { if (ipAddress == 0) { return null; } return String.format(Locale.ENGLISH, "%d.%d.%d.%d", ipAddress & 0xff, ipAddress >> 8 & 0xff, ipAddress >> 16 & 0xff, ipAddress >> 24 & 0xff); } WifiStateChangeService(); static void start(Context context, @Nullable Intent intent); }
WifiStateChangeService extends IntentService { static String formatIpAddress(int ipAddress) { if (ipAddress == 0) { return null; } return String.format(Locale.ENGLISH, "%d.%d.%d.%d", ipAddress & 0xff, ipAddress >> 8 & 0xff, ipAddress >> 16 & 0xff, ipAddress >> 24 & 0xff); } WifiStateChangeService(); static void start(Context context, @Nullable Intent intent); static final String BROADCAST; static final String EXTRA_STATUS; }