android连接wifi时获取广播地址代码_Android

复制代码 代码如下:

private InetAddress getBroadcastAddress() throws IOException {
WifiManager myWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
DhcpInfo myDhcpInfo = myWifiManager.getDhcpInfo();
if (myDhcpInfo == null) {
System.out.println("Could not get broadcast address");
return null;
}
int broadcast = (myDhcpInfo.ipAddress & myDhcpInfo.netmask)
| ~myDhcpInfo.netmask;
byte[] quads = new byte[4];
for (int k = 0; k < 4; k++)
quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
return InetAddress.getByAddress(quads);
}

时间: 2024-07-31 05:42:20

android连接wifi时获取广播地址代码_Android的相关文章

android连接wifi时获取广播地址代码

复制代码 代码如下: private InetAddress getBroadcastAddress() throws IOException { WifiManager myWifiManager = (WifiManager) getSystemService(WIFI_SERVICE); DhcpInfo myDhcpInfo = myWifiManager.getDhcpInfo(); if (myDhcpInfo == null) { System.out.println("Could

android网络编程之android连接网络的简单示例代码_Android

复制代码 代码如下: private void callToWebSrvice() {     ConnectivityManager connManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);     if (connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State

Android判断是Wifi还是4G网络代码_Android

本文实例为大家分享了Android判断是Wifi还是4G网络的具体代码,供大家参考,具体内容如下 package com.chengxinet.bobo.utils; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.telephony.TelephonyManager; /** * Created by Ad

Android 连接Wifi和创建Wifi热点 demo

[java] view plaincopy android的热点功能不可见,用了反射的技术搞定之外.   [java] view plaincopy Eclipse设置语言为utf-8才能查看中文注释   上代码: MainActivity.java [java] view plaincopy package com.widget.hotspot;      import android.os.Bundle;   import android.app.Activity;   import and

Android 底部导航控件实例代码_Android

一.先给大家展示下最终效果 通过以上可以看到,图一是简单的使用,图二.图三中为结合ViewPager共同使用,而且都可以随ViewPager的滑动渐变色,不同点是图二为选中非选中两张图片,图三的选中非选中是一张图片只是做了颜色变化. 二. 需求 我们希望做可以做成这样的,可以在xml布局中引入控件并绑定数据,在代码中设置监听回调,并且配置使用要非常简单! 三.需求分析 根据我们多年做不明确需求项目的经验,以上需求还算明确.那么我们可以采用在LinearLayout添加子View控件,这个子Vie

Android自定义控件下拉刷新实例代码_Android

实现效果: 图片素材: --> 首先, 写先下拉刷新时的刷新布局 pull_to_refresh.xml: <resources> <string name="app_name">PullToRefreshTest</string> <string name="pull_to_refresh">下拉可以刷新</string> <string name="release_to_refre

Android 保存Fragment 切换状态实例代码_Android

前言  一般频繁切换Fragment会导致频繁的释放和创建,如果Fragment比较臃肿体验就非常不好了,这里分享一个方法.  正文  一.应用场景   1.不使用ViewPager   2.不能用replace来切换Fragment,会导致Fragment释放(调用onDestroyView)  二.实现 1.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:

Android 嵌套Fragment的使用实例代码_Android

前言   之前的文章有介绍ActivityGroup,不少人问嵌套使用的问题,同样的需求在Fragment中也存在,幸好在最新的Android support 包已经支持这一特性!这里就跳过Fragment的介绍,需要注意的是TabActivity已经被标记为弃用(deprecated). 正文  一.准备   关于最新的Android兼容包的介绍,参见官网.可以在android sdk目录下extras/android/support/v13/android-support-v13.jar找到

Android 动态添加Fragment的实例代码_Android

1.fragment1布局及代码 布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width=&quo