android显示wifi信号强度以及周边信号(源代码)
2013-08-28 21:50
232 查看
先把activity_main.xml文件代码贴出来.TextView充满屏幕
AndroidMenifest.xml中,加入两行,作用:获取权限
最后是MainActivity.java中的程序:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <!-- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/white" /> --> <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:textColor="@android:color/black" android:textSize="25sp" /> </LinearLayout>
AndroidMenifest.xml中,加入两行,作用:获取权限
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
最后是MainActivity.java中的程序:
package com.example.wifistrength; import java.util.List; import android.net.wifi.ScanResult; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.view.Menu; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String wserviceName = Context.WIFI_SERVICE; WifiManager wm = (WifiManager) getSystemService(wserviceName); WifiInfo info = wm.getConnectionInfo(); int strength = info.getRssi(); int speed = info.getLinkSpeed(); String units = WifiInfo.LINK_SPEED_UNITS; String ssid = info.getSSID(); tv = (TextView) findViewById(R.id.textView1); List<ScanResult> results = wm.getScanResults(); String otherwifi = "The existing network is: \n\n"; for (ScanResult result : results) { otherwifi += result.SSID + ":" + result.level + "\n"; } String text = "We are connecting to " + ssid + " at " + String.valueOf(speed) + " " + String.valueOf(units) + ". Strength : " + strength; otherwifi += "\n\n"; otherwifi += text; tv.setText(otherwifi); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }结果图:
相关文章推荐
- android显示wifi信号强度以及周边信号(源代码)
- Android显示wifi信号强度以及周边信号的代码
- android sdk 编译--如何将源代码加入android.jar以及make原理
- 仿Android联系人SideBar排序,根据拼音A-Z字母快速导航联系人姓名,以及输入搜索条件过滤,显示姓名的文字图片,添加挤压动画
- android—DatePicker 和TimePicker显示日期以及使用TimePickerDialog,DatePickerDialog来专门实现时间选择对话框
- Android在界面中显示以及输入文本信息...
- Android的intent:基础概念以及显示/隐式使用Intent && 通过intent返回结果
- android中隐藏与显示软键盘以及不自动弹出键盘的方法
- android wifi移植statusbar信号只显示一格的问题
- android sdk 编译--如何将源代码加入android.jar,以及make原理
- 举例说明android中Bitmap、ListView以及ImageView的综合使用---显示图片并获取图片的宽和高
- Android 文本阅读以及TextView指定字符高亮显示
- android隐藏以及显示软键盘以及不自动弹出键盘的方法
- android 根据SD卡中图片路径读取并显示SD中的图片——源代码
- Android腾讯微博客户端开发六:给用户加VIP认证以及美化微博显示内容
- Android在TextView中显示html标签以及异步加载网页图片
- Android 显示单位px和dip以及sp的区别
- Android圆盘菜单(修改了网络上现有的demo总是显示第一个的bug,以及增加了点击事件)