Android WiFi管理(WIFI_SERVICE)

分类: Android2011-11-24 10:52 2000人阅读 评论(1) 收藏 举报

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.entel.research"
  4. android:versionCode="1"
  5. android:versionName="1.0" >
  6. <uses-sdk android:minSdkVersion="7" />
  7. <application
  8. android:icon="@drawable/ic_launcher"
  9. android:label="@string/app_name" android:debuggable="true">
  10. <activity
  11. android:label="@string/app_name"
  12. android:name=".WifiManagerActivity" >
  13. <intent-filter >
  14. <action android:name="android.intent.action.MAIN" />
  15. <category android:name="android.intent.category.LAUNCHER" />
  16. </intent-filter>
  17. </activity>
  18. </application>
  19. <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  20. <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
  21. <uses-permission android:name="android.permission.WAKE_LOCK" />
  22. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  23. </manifest>
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text="@string/hello" />
  10. <Button
  11. android:id="@+id/wifiManager_open"
  12. android:layout_width="fill_parent"
  13. android:layout_height="wrap_content"
  14. android:text="打开WiFi" />
  15. <Button
  16. android:id="@+id/wifiManager_close"
  17. android:layout_width="fill_parent"
  18. android:layout_height="wrap_content"
  19. android:text="关闭WiFi" />
  20. <Button
  21. android:id="@+id/wifiManager_check"
  22. android:layout_width="fill_parent"
  23. android:layout_height="wrap_content"
  24. android:text="显示WiFi状态" />
  25. <Button
  26. android:id="@+id/wifiManager_WIFI_SETTINGS"
  27. android:layout_width="fill_parent"
  28. android:layout_height="wrap_content"
  29. android:text="WiFi网络设置" />
  30. <Button
  31. android:id="@+id/threeGManager_State"
  32. android:layout_width="fill_parent"
  33. android:layout_height="wrap_content"
  34. android:text="显示3G边境状态" />
  35. <Button
  36. android:id="@+id/wifiManager_WIRELESS_SETTINGS"
  37. android:layout_width="fill_parent"
  38. android:layout_height="wrap_content"
  39. android:text="无线网络配置" />
  40. </LinearLayout>
  1. package com.entel.research;
  2. import android.app.Activity;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.net.ConnectivityManager;
  6. import android.net.NetworkInfo.State;
  7. import android.net.wifi.WifiManager;
  8. import android.os.Bundle;
  9. import android.provider.Settings;
  10. import android.view.View;
  11. import android.view.View.OnClickListener;
  12. import android.widget.Button;
  13. import android.widget.Toast;
  14. public class WifiManagerActivity extends Activity
  15. {
  16. @Override
  17. public void onCreate(Bundle savedInstanceState)
  18. {
  19. super.onCreate(savedInstanceState);
  20. setContentView(R.layout.main);
  21. Button wifiManager_open = (Button) findViewById(R.id.wifiManager_open);
  22. Button wifiManager_close = (Button) findViewById(R.id.wifiManager_close);
  23. Button wifiManager_check = (Button) findViewById(R.id.wifiManager_check);
  24. Button wifiManager_WIFI_SETTINGS = (Button) findViewById(R.id.wifiManager_WIFI_SETTINGS);
  25. Button wifiManager_WIRELESS_SETTINGS = (Button) findViewById(R.id.wifiManager_WIRELESS_SETTINGS);
  26. Button threeGManager_State = (Button) findViewById(R.id.threeGManager_State);
  27. final WifiManager wifiManager = (WifiManager) WifiManagerActivity.this
  28. .getSystemService(Context.WIFI_SERVICE);
  29. final ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  30. wifiManager_open.setOnClickListener(new OnClickListener()
  31. {
  32. public void onClick(View v)
  33. {
  34. wifiManager.setWifiEnabled(true);
  35. Toast.makeText(WifiManagerActivity.this, "Wifi开启",
  36. Toast.LENGTH_SHORT).show();
  37. }
  38. });
  39. wifiManager_close.setOnClickListener(new OnClickListener()
  40. {
  41. public void onClick(View v)
  42. {
  43. if (wifiManager.isWifiEnabled())
  44. {
  45. wifiManager.setWifiEnabled(false);
  46. Toast.makeText(WifiManagerActivity.this, "Wifi关闭",
  47. Toast.LENGTH_SHORT).show();
  48. }
  49. Toast.makeText(WifiManagerActivity.this, "Wifi关闭",
  50. Toast.LENGTH_SHORT).show();
  51. }
  52. });
  53. wifiManager_check.setOnClickListener(new OnClickListener()
  54. {
  55. public void onClick(View v)
  56. {
  57. String result = null;
  58. switch (wifiManager.getWifiState())
  59. {
  60. case WifiManager.WIFI_STATE_DISABLED:
  61. result = "WIFI已关闭";
  62. break;
  63. case WifiManager.WIFI_STATE_DISABLING:
  64. result = "WIFI正在关闭中";
  65. break;
  66. case WifiManager.WIFI_STATE_ENABLED:
  67. result = "WIFI已启用";
  68. break;
  69. case WifiManager.WIFI_STATE_ENABLING:
  70. result = "WIFI正在启动中";
  71. break;
  72. case WifiManager.WIFI_STATE_UNKNOWN:
  73. result = "未知WIFI状态";
  74. break;
  75. }
  76. Toast.makeText(WifiManagerActivity.this, result, Toast.LENGTH_SHORT)
  77. .show();
  78. }
  79. });
  80. wifiManager_WIFI_SETTINGS.setOnClickListener(new OnClickListener()
  81. {
  82. public void onClick(View v)
  83. {
  84. startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
  85. }
  86. });
  87. threeGManager_State.setOnClickListener(new OnClickListener()
  88. {
  89. public void onClick(View v)
  90. {
  91. State mobile = conMan.getNetworkInfo(
  92. ConnectivityManager.TYPE_MOBILE).getState();
  93. Toast.makeText(WifiManagerActivity.this, mobile.toString(),
  94. Toast.LENGTH_SHORT).show();
  95. }
  96. });
  97. wifiManager_WIRELESS_SETTINGS.setOnClickListener(new OnClickListener()
  98. {
  99. public void onClick(View v)
  100. {
  101. startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
  102. }
  103. });
  104. }
  105. }

版权声明:本文为博主原创文章,未经博主允许不得转载。

http://blog.csdn.net/sbvfhp/article/details/7007090
http://www.2cto.com/kf/201111/112219.html

Android WiFi管理(WIFI_SERVICE)的更多相关文章

  1. Android wifi管理类:WifiAdmin

    1.wifi的五种状态: WIFI_STATE_DISABLED   WIFI网卡不可用 WIFI_STATE_DISABLING WIFI网卡正在关闭 WIFI_STATE_ENABLED     ...

  2. Android Wi-Fi基本操作

    从用户角度看,Android Wi-Fi模块自下向上可以看为5层:硬件驱动程序,wpa_suppplicant,JNI,WiFi API,WifiSettings应用程序. 1.wpa_supplic ...

  3. android -------- WIFI 详解

    今天简单的来聊一下安卓开发中的Wifi,一些常用的基础,主要分为两部分: 1:WiFi的信息 2:WiFi的搜索和连接 现在app大多都需要从网络上获得数据.所以访问网络是在所难免.但是在访问网络之前 ...

  4. Android WiFi开发

    概述 介绍Android WiFi的扫描.连接.信息.以及WiFi热点等等的实现,并用代码实现. 详细 代码下载:http://www.demodashi.com/demo/10660.html 一. ...

  5. android wifi 热点、socket通讯

    WiFi管理工具类 package com.wyf.app.common; import java.lang.reflect.InvocationTargetException; import jav ...

  6. Android WiFi开发教程(一)——WiFi热点的创建与关闭

    相对于BlueTooth,WiFi是当今使用最广的一种无线网络传输技术, 几乎所有智能手机.平板电脑和笔记本电脑都支持Wi-Fi上网.因此,掌握基本的WiFI开发技术是非常必要的.本教程将围绕一个小D ...

  7. Android WiFi系统架构【转】

    本文转载自:http://blog.csdn.net/liuhaomatou/article/details/40398753 在了解WIFI模块的系统架构之前.我心中就有一个疑问,那么Android ...

  8. Android WIFI 分析(一)

    本文基于<深入理解Android WiFi NFC和GPS 卷>和 Android N 代码结合分析   WifiService 是 Frameworks中负责wifi功能的核心服务,它主 ...

  9. android wifi驱动移植详细过程

    转自:http://bbs.imp3.net/thread-10558924-1-1.html 对于刚入手android没多久的人来说,android wifi 驱动的移植确实还是有难度的,不过参考了 ...

随机推荐

  1. html元素中class属性值多个空格分格是什么意思?

    即指定多个class,这是bootstrap常干的事,比如 <div class="alert alert-info"> 请问,这两个class之间的关系是什么,二者的 ...

  2. hdu_5807_Keep In Touch(分段dp)

    题目链接:hdu_5807_Keep In Touch 题意: 在Byteland一共有nn个城市,编号依次为11到nn,同时有mm条单向道路连接着这些城市,其中第ii条道路的起点为u_iu​i​​, ...

  3. Sharepoint 弹出消息提示框 .

    在event receiver中如何弹出一个类似winform中messagebox.show 的框? 那我要对用户显示一些错误信息或者提示信息怎么搞? 1. 如果是在ItemAdding或者其他进行 ...

  4. Http Post与Get等

    Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP ...

  5. 去掉uitableveiw多余的分割线

    UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; [_tableView setTableFooterView:v];

  6. git clone分支

    有时git clone下来会出现很多branch,更麻烦的是如果主分支没代码那你就只能看到.git目录了.如下面的这个: $ git clonegit://gitorious.org/android- ...

  7. CSS中!important的使用 转

    本篇文章使用最新的IE10以及firefox与chrome测试(截止2013年5月27日22::) CSS的原理: 我们知道,CSS写在不同的地方有不同的优先级, .css文件中的定义 < 元素 ...

  8. UITextfield的一些属性

    //设置左视图 不用设置frame UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@&quo ...

  9. inserted触发器,一张表插入数据时,同时向另外一张表插入数据

    有时候,一个服务器上有多个数据库,需要向其中一个数据库的表中插入数据时, 同时向另外一个数据的表里插入数据. 可以利用触发器和同义词(建立同义词的方法省略), 在一个数据库的表里插入数据时,同时向另外 ...

  10. 转: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 ...