搜索
熱門(mén)關(guān)鍵詞:
Dialog
CMOS
運算放大器
全志
Imagination
手機版
官方微博
微信公眾號
登錄
|
免費注冊
首頁(yè)
新聞
新品
文章
下載
電路
問(wèn)答
視頻
職場(chǎng)
雜談
會(huì )展
工具
博客
論壇
在線(xiàn)研討會(huì )
技術(shù)頻道:
單片機/處理器
FPGA
軟件/編程
電源技術(shù)
模擬電子
PCB設計
測試測量
MEMS
系統設計
無(wú)源/分立器件
音頻/視頻/顯示
應用頻道:
消費電子
工業(yè)/測控
汽車(chē)電子
通信/網(wǎng)絡(luò )
醫療電子
機器人
當前位置:
EEChina首頁(yè)
›
通信/網(wǎng)絡(luò )
›
文章
Android wifi 信號強度的顯示以及周邊信號的代碼
發(fā)布時(shí)間:2013-8-30 15:54 發(fā)布者:
reggae
關(guān)鍵詞:
信號強度
,
Android
,
wifi
先把activity_main.xml文件代碼貼出來(lái).TextView充滿(mǎn)屏幕
01
02
xmlns:tools="http://schemas.android.com/tools"
03
android:layout_width="match_parent"
04
android:layout_height="match_parent"
05
android:paddingBottom="@dimen/activity_vertical_margin"
06
android:paddingLeft="@dimen/activity_horizontal_margin"
07
android:paddingRight="@dimen/activity_horizontal_margin"
08
android:paddingTop="@dimen/activity_vertical_margin"
09
tools:context=".MainActivity" >
10
11
17
18
android:id="@+id/textView1"
19
android:layout_width="match_parent"
20
android:layout_height="match_parent"
21
android:gravity="center"
22
android:textColor="@android:color/black"
23
android:textSize="25sp" />
24
25
復制代碼
Android
Menifest.xml中,加入兩行,作用:獲取權限
最后是MainActivity.java中的程序:
查看源碼打印?
01
package com.example.wifistrength;
02
03
import java.util.List;
04
05
import android.net.wifi.ScanResult;
06
import android.net.wifi.WifiInfo;
07
import android.net.wifi.WifiManager;
08
import android.os.Bundle;
09
import android.app.Activity;
10
import android.content.Context;
11
import android.view.Menu;
12
import android.widget.TextView;
13
import android.widget.Toast;
14
15
public class MainActivity extends Activity {
16
17
TextView tv;
18
19
@Override
20
protected void onCreate(Bundle savedInstanceState) {
21
super.onCreate(savedInstanceState);
22
setContentView(R.layout.activity_main);
23
24
String wserviceName = Context.
WIFI
_SERVICE;
25
WifiManager wm = (WifiManager) getSystemService(wserviceName);
26
27
WifiInfo info = wm.getConnectionInfo();
28
int strength = info.getRssi();
29
int speed = info.getLinkSpeed();
30
String units = WifiInfo.LINK_SPEED_UNITS;
31
String ssid = info.getSSID();
32
33
tv = (TextView) findViewById(R.id.textView1);
34
35
List results = wm.getScanResults();
36
String otherwifi = "The existing network is: \n\n";
37
38
for (ScanResult result : results) {
39
otherwifi += result.SSID + ":" + result.level + "\n";
40
}
41
42
String text = "We are connecting to " + ssid + " at " + String.valueOf(speed) + " " + String.valueOf(units) + ". Strength : " + strength;
43
otherwifi += "\n\n";
44
otherwifi += text;
45
46
tv.setText(otherwifi);
47
48
}
49
50
51
@Override
52
public boolean onCreateOptionsMenu(Menu menu) {
53
// Inflate the menu; this adds items to the action bar if it is present.
54
getMenuInflater().inflate(R.menu.main, menu);
55
return true;
56
}
57
58
}
復制代碼
結果圖:
希望本文對廣大安卓開(kāi)發(fā)者有所幫助,感謝閱讀本文。更多
安卓技術(shù)問(wèn)題
歡迎加群探討:
278744577
,驗證碼:
eec
,不寫(xiě)驗證不予通過(guò)喲~
本文地址:
http://selenalain.com/thread-120145-1-1.html
【打印本頁(yè)】
本站部分文章為轉載或網(wǎng)友發(fā)布,目的在于傳遞和分享信息,并不代表本網(wǎng)贊同其觀(guān)點(diǎn)和對其真實(shí)性負責;文章版權歸原作者及原出處所有,如涉及作品內容、版權和其它問(wèn)題,我們將根據著(zhù)作權人的要求,第一時(shí)間更正或刪除。
相關(guān)文章
IPQ9574,IPQ5332,IPQ9570-WiFi 7 chip diversity: Performance, application and market differences analysis
IPQ4019 vs. IPQ5018-Comprehensive Comparison of WiFi Solutions
丟掉數據線(xiàn),你還會(huì )調試Android設備嗎?
QCN6274 and QCN9074 chip series Comprehensive comparison
Qualcomm Chip IPQ9574/IPQ9554 and QCN9074/QCN6024-The Wireless Miracles
WiFi7-IPQ9574 and WiFi6 IPQ8072 cpus respectively represent the highest performance in the WiFi phase.
How do IPQ9574 and IPQ9554 connect QCN9274 for WiFi7 connectivity?
SFP with or without -11AC-IPQ4019 VS 11AX-IPQ6010 motherboards What is the difference?
Explore the IPQ5018 and IPQ8072 chip contest, who will lead the future network revolution?
IPQ4019/IPQ4029 router is used to develop TDMA under openwrt - Better performance and efficiency for wireless networks.
網(wǎng)友評論
高級模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登錄后才可以發(fā)表評論
登錄
|
立即注冊
發(fā)表評論
貿澤電子有獎問(wèn)答視頻,答對領(lǐng)10元微信紅包
廠(chǎng)商推薦
Microchip視頻專(zhuān)區
利用模擬開(kāi)發(fā)工具生態(tài)系統進(jìn)行安全電路設計
你仿真過(guò)嗎?使用免費的MPLAB Mindi模擬仿真器降低設計風(fēng)險
我們是Microchip
想要避免發(fā)生災難,就用MPLAB SiC電源仿真器!
貿澤電子(Mouser)專(zhuān)區
相關(guān)視頻
Linux & Android-Debugging
12869
追趕WiFi浪潮-泰克最新802.11a/b/g/n/ac測試方案
12729
特殊應用:利用Apple和Android控制儀器的工具
12248
關(guān)于我們
-
服務(wù)條款
-
使用指南
-
站點(diǎn)地圖
-
友情鏈接
-
聯(lián)系我們
電子工程網(wǎng)
© 版權所有
京ICP備16069177號
| 京公網(wǎng)安備11010502021702
快速回復
返回頂部
返回列表
午夜高清国产拍精品福利|亚洲色精品88色婷婷七月丁香|91久久精品无码一区|99久久国语露脸精品|动漫卡通亚洲综合专区48页