Android WiFi管理(WIFI_SERVICE)
Android WiFi管理(WIFI_SERVICE)

- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.entel.research"
- android:versionCode="1"
- android:versionName="1.0" >
- <uses-sdk android:minSdkVersion="7" />
- <application
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name" android:debuggable="true">
- <activity
- android:label="@string/app_name"
- android:name=".WifiManagerActivity" >
- <intent-filter >
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
- <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
- <uses-permission android:name="android.permission.WAKE_LOCK" />
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- </manifest>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello" />
- <Button
- android:id="@+id/wifiManager_open"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="打开WiFi" />
- <Button
- android:id="@+id/wifiManager_close"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="关闭WiFi" />
- <Button
- android:id="@+id/wifiManager_check"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="显示WiFi状态" />
- <Button
- android:id="@+id/wifiManager_WIFI_SETTINGS"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="WiFi网络设置" />
- <Button
- android:id="@+id/threeGManager_State"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="显示3G边境状态" />
- <Button
- android:id="@+id/wifiManager_WIRELESS_SETTINGS"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="无线网络配置" />
- </LinearLayout>
- package com.entel.research;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo.State;
- import android.net.wifi.WifiManager;
- import android.os.Bundle;
- import android.provider.Settings;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.Toast;
- public class WifiManagerActivity extends Activity
- {
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button wifiManager_open = (Button) findViewById(R.id.wifiManager_open);
- Button wifiManager_close = (Button) findViewById(R.id.wifiManager_close);
- Button wifiManager_check = (Button) findViewById(R.id.wifiManager_check);
- Button wifiManager_WIFI_SETTINGS = (Button) findViewById(R.id.wifiManager_WIFI_SETTINGS);
- Button wifiManager_WIRELESS_SETTINGS = (Button) findViewById(R.id.wifiManager_WIRELESS_SETTINGS);
- Button threeGManager_State = (Button) findViewById(R.id.threeGManager_State);
- final WifiManager wifiManager = (WifiManager) WifiManagerActivity.this
- .getSystemService(Context.WIFI_SERVICE);
- final ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
- wifiManager_open.setOnClickListener(new OnClickListener()
- {
- public void onClick(View v)
- {
- wifiManager.setWifiEnabled(true);
- Toast.makeText(WifiManagerActivity.this, "Wifi开启",
- Toast.LENGTH_SHORT).show();
- }
- });
- wifiManager_close.setOnClickListener(new OnClickListener()
- {
- public void onClick(View v)
- {
- if (wifiManager.isWifiEnabled())
- {
- wifiManager.setWifiEnabled(false);
- Toast.makeText(WifiManagerActivity.this, "Wifi关闭",
- Toast.LENGTH_SHORT).show();
- }
- Toast.makeText(WifiManagerActivity.this, "Wifi关闭",
- Toast.LENGTH_SHORT).show();
- }
- });
- wifiManager_check.setOnClickListener(new OnClickListener()
- {
- public void onClick(View v)
- {
- String result = null;
- switch (wifiManager.getWifiState())
- {
- case WifiManager.WIFI_STATE_DISABLED:
- result = "WIFI已关闭";
- break;
- case WifiManager.WIFI_STATE_DISABLING:
- result = "WIFI正在关闭中";
- break;
- case WifiManager.WIFI_STATE_ENABLED:
- result = "WIFI已启用";
- break;
- case WifiManager.WIFI_STATE_ENABLING:
- result = "WIFI正在启动中";
- break;
- case WifiManager.WIFI_STATE_UNKNOWN:
- result = "未知WIFI状态";
- break;
- }
- Toast.makeText(WifiManagerActivity.this, result, Toast.LENGTH_SHORT)
- .show();
- }
- });
- wifiManager_WIFI_SETTINGS.setOnClickListener(new OnClickListener()
- {
- public void onClick(View v)
- {
- startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
- }
- });
- threeGManager_State.setOnClickListener(new OnClickListener()
- {
- public void onClick(View v)
- {
- State mobile = conMan.getNetworkInfo(
- ConnectivityManager.TYPE_MOBILE).getState();
- Toast.makeText(WifiManagerActivity.this, mobile.toString(),
- Toast.LENGTH_SHORT).show();
- }
- });
- wifiManager_WIRELESS_SETTINGS.setOnClickListener(new OnClickListener()
- {
- public void onClick(View v)
- {
- startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
- }
- });
- }
- }
版权声明:本文为博主原创文章,未经博主允许不得转载。
- 上一篇Android 面试题
- 下一篇Android连接到加密网络
- http://blog.csdn.net/sbvfhp/article/details/7007090
- http://www.2cto.com/kf/201111/112219.html
Android WiFi管理(WIFI_SERVICE)的更多相关文章
- Android wifi管理类:WifiAdmin
1.wifi的五种状态: WIFI_STATE_DISABLED WIFI网卡不可用 WIFI_STATE_DISABLING WIFI网卡正在关闭 WIFI_STATE_ENABLED ...
- Android Wi-Fi基本操作
从用户角度看,Android Wi-Fi模块自下向上可以看为5层:硬件驱动程序,wpa_suppplicant,JNI,WiFi API,WifiSettings应用程序. 1.wpa_supplic ...
- android -------- WIFI 详解
今天简单的来聊一下安卓开发中的Wifi,一些常用的基础,主要分为两部分: 1:WiFi的信息 2:WiFi的搜索和连接 现在app大多都需要从网络上获得数据.所以访问网络是在所难免.但是在访问网络之前 ...
- Android WiFi开发
概述 介绍Android WiFi的扫描.连接.信息.以及WiFi热点等等的实现,并用代码实现. 详细 代码下载:http://www.demodashi.com/demo/10660.html 一. ...
- android wifi 热点、socket通讯
WiFi管理工具类 package com.wyf.app.common; import java.lang.reflect.InvocationTargetException; import jav ...
- Android WiFi开发教程(一)——WiFi热点的创建与关闭
相对于BlueTooth,WiFi是当今使用最广的一种无线网络传输技术, 几乎所有智能手机.平板电脑和笔记本电脑都支持Wi-Fi上网.因此,掌握基本的WiFI开发技术是非常必要的.本教程将围绕一个小D ...
- Android WiFi系统架构【转】
本文转载自:http://blog.csdn.net/liuhaomatou/article/details/40398753 在了解WIFI模块的系统架构之前.我心中就有一个疑问,那么Android ...
- Android WIFI 分析(一)
本文基于<深入理解Android WiFi NFC和GPS 卷>和 Android N 代码结合分析 WifiService 是 Frameworks中负责wifi功能的核心服务,它主 ...
- android wifi驱动移植详细过程
转自:http://bbs.imp3.net/thread-10558924-1-1.html 对于刚入手android没多久的人来说,android wifi 驱动的移植确实还是有难度的,不过参考了 ...
随机推荐
- html元素中class属性值多个空格分格是什么意思?
即指定多个class,这是bootstrap常干的事,比如 <div class="alert alert-info"> 请问,这两个class之间的关系是什么,二者的 ...
- hdu_5807_Keep In Touch(分段dp)
题目链接:hdu_5807_Keep In Touch 题意: 在Byteland一共有nn个城市,编号依次为11到nn,同时有mm条单向道路连接着这些城市,其中第ii条道路的起点为u_iui, ...
- Sharepoint 弹出消息提示框 .
在event receiver中如何弹出一个类似winform中messagebox.show 的框? 那我要对用户显示一些错误信息或者提示信息怎么搞? 1. 如果是在ItemAdding或者其他进行 ...
- Http Post与Get等
Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP ...
- 去掉uitableveiw多余的分割线
UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; [_tableView setTableFooterView:v];
- git clone分支
有时git clone下来会出现很多branch,更麻烦的是如果主分支没代码那你就只能看到.git目录了.如下面的这个: $ git clonegit://gitorious.org/android- ...
- CSS中!important的使用 转
本篇文章使用最新的IE10以及firefox与chrome测试(截止2013年5月27日22::) CSS的原理: 我们知道,CSS写在不同的地方有不同的优先级, .css文件中的定义 < 元素 ...
- UITextfield的一些属性
//设置左视图 不用设置frame UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@&quo ...
- inserted触发器,一张表插入数据时,同时向另外一张表插入数据
有时候,一个服务器上有多个数据库,需要向其中一个数据库的表中插入数据时, 同时向另外一个数据的表里插入数据. 可以利用触发器和同义词(建立同义词的方法省略), 在一个数据库的表里插入数据时,同时向另外 ...
- 转:12C CDB and pdb with sql developer
How to install the 12c DB and use the Pluggable DB with SQL DeveloperGoal To give a path to install ...