service--取得手机网络信息
2014-02-25 21:38
351 查看
package org.lxh.demo; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.telephony.TelephonyManager; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; public class MyTelephoneManagerDemo extends Activity { private ListView infolist = null; // ListView列表 private TelephonyManager manager = null; // 手机管理器 private ListAdapter adapter = null; // 适配器组件 private List<String> all = new ArrayList<String>(); // 保存信息 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.main); // 调用布局管理器 this.infolist = (ListView) super .findViewById(R.id.infolist); // 取得组件 this.manager = (TelephonyManager) super .getSystemService(Context.TELEPHONY_SERVICE); // 取得手机服务 this.list(); // 列表显示 } private void list() { // 执行列表显示操作 this.all.add(this.manager.getLine1Number() == null ? "没有手机号码" : "手机号码:" + this.manager.getLine1Number()); // 取得手机号码 this.all.add(this.manager.getNetworkOperatorName() == null ? "没有移动服务商" : "移动服务商:" + this.manager.getNetworkOperatorName()); // 取得移动商名称 if (this.manager.getPhoneType() == TelephonyManager.NETWORK_TYPE_CDMA) {// 判断网络类型 this.all.add("移动网络:CDMA"); } else if (this.manager.getPhoneType() == TelephonyManager.NETWORK_TYPE_GPRS) { this.all.add("移动网络:GPRS"); } else { this.all.add("移动网络:未知"); } if (this.manager.getNetworkType() == TelephonyManager.PHONE_TYPE_GSM) { // 判断电话网络类型 this.all.add("网络类型:GSM"); } else if (this.manager.getNetworkType() == TelephonyManager.PHONE_TYPE_CDMA) { this.all.add("网络类型:CDMA"); } else { this.all.add("网络类型:未知"); } this.all.add("是否漫游:" + (this.manager.isNetworkRoaming() ? "漫游" : "非漫游")); // 是否是漫游 this.adapter = new ArrayAdapter<String>(this, // 实例化ArrayAdapter android.R.layout.simple_list_item_1, // 定义布局文件 this.all); // 定义显示数据 this.infolist.setAdapter(this.adapter); // 设置数据 } }
<?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"> <ListView android:id="@+id/infolist" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.lxh.demo" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MyTelephoneManagerDemo" 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> </manifest>
相关文章推荐
- HttpServletRequest
- Http协议的流程以及相关内容(1.0与1.1的区别)
- http status汇总
- 网络IPC:套接字之非阻塞和异步I/O
- [DEVDIV原创] 使用HttpURLConnection发送Post/Get请求
- 网络IPC:套接字之带外数据
- 虚拟机安装Centos6.5之后的网络配置
- 黑马程序员---TCP传输
- 网络舆情监控系统的爬虫子系统开发总结
- Linux网络设置
- QUdpSocket进行网络传输
- HttpClient4.x的一些使用
- python 网络爬虫
- 网络IPC:套接字之套接字选项
- 使用python中的HTTPServer创建本地站点
- Windows Server 2003的一些优化设置 (转至网络)
- 网络阅读开篇
- HTTP协议中的5类状态码
- 几个好的“光网络”期刊和会议
- 移动应用-使用tcpdump抓包