mars老师[Android开发视频教学]01_23 WIFI网络操作
mars老师[Android开发视频教学]01_23 WIFI网络操作
创建项目:Wifi
项目运行截图:
布局文件:main.xml
[html]
<SPAN style="FONT-SIZE: 18px; FONT-FAMILY: KaiTi_GB2312"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/startWifi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="启动手机的wifi网卡"
/>
<Button
android:id="@+id/stopWifi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="关闭手机的wifi网卡"
/>
<Button
android:id="@+id/checkWifi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="检查当前wifi网卡状态"
/>
</LinearLayout></SPAN>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/startWifi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="启动手机的wifi网卡"
/>
<Button
android:id="@+id/stopWifi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="关闭手机的wifi网卡"
/>
<Button
android:id="@+id/checkWifi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="检查当前wifi网卡状态"
/>
</LinearLayout>
在manifest文件设置权限:AndroidManifest.xml
[html]
<SPAN style="FONT-SIZE: 18px; FONT-FAMILY: KaiTi_GB2312"><?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mars.wifi" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".WifiActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
<!-- 以下是使用wifi访问网络所需要的权限 -->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
</manifest> </SPAN>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mars.wifi" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".WifiActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
<!-- 以下是使用wifi访问网络所需要的权限 -->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
</manifest>
==>WifiActivity.java
[java] view plaincopyprint?
<SPAN style="FONT-SIZE: 18px; FONT-FAMILY: KaiTi_GB2312">package mars.wifi;
import android.app.Activity;
import android.content.Context;
import
补充:移动开发 , Android ,