Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 588|回复: 0

[实例教程]Android 取sim所有信息

[复制链接]

该用户从未签到

发表于 2011-10-22 12:30:46 | 显示全部楼层 |阅读模式
我们这篇文章主要讲的就是怎么样来读取我们sim里的所有信息,这个其实对我们也是很重要的,下面我们就来看看怎么样用代码来获取吧。

       主类:SimData.java

java代码: public class SimData extends ListActivity {

private TelephonyManager telMgr;

private List<String> item=new ArrayList<String>();



private List<String> value=new ArrayList<String>();

@SuppressWarnings(“static-access”)



@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

/* 载入main.xml Layout */

setContentView(R.layout.main);



//创建电话管理与手机建立连接

telMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);



/* 将取得的信息写入List中 */

/* 取得SIM卡状态 */

item.add(getResources().getText(R.string.str_list0).toString());

if(telMgr.getSimState()==telMgr.SIM_STATE_READY){

value.add(“良好”);

}else if(telMgr.getSimState()==telMgr.SIM_STATE_ABSENT){



value.add(“无SIM卡”);

}else if(telMgr.getSimState() == telMgr.SIM_STATE_NETWORK_LOCKED){



value.add(“需要NetWork PIN 解锁”);



}else if(telMgr.getSimState() == telMgr.SIM_STATE_PIN_REQUIRED){



value.add(“需要SIM卡的PIN解锁”);



}else if(telMgr.getSimState() == telMgr.SIM_STATE_PUK_REQUIRED){



value.add(“需要SIM卡的PUK解锁”);



}else if(telMgr.getSimState() == telMgr.SIM_STATE_UNKNOWN){



value.add(“SIM卡状态未知”);



}



/* 取得SIM卡卡号/IMEI:手机串号 */

item.add(getResources().getText(R.string.str_list1).toString());

if(telMgr.getSimSerialNumber()!=null){

value.add(telMgr.getSimSerialNumber());

}else{

value.add(“无法取得”);

}





/* 取得SIM卡卡号/IMSI:国际移动用户识别码*/



item.add(getResources().getText(R.string.str_list2).toString());

if(telMgr.getSubscriberId()!=null){

value.add(telMgr.getSubscriberId());

}else{

value.add(“无法取得”);

}



/* 取得SIM卡供货商代码 */

item.add(getResources().getText(R.string.str_list3).toString());

if(telMgr.getSimOperator().equals(“”)){

value.add(“无法取得”);

}else{

value.add(telMgr.getSimOperator());

}



/* 取得SIM卡供货商名称 */

item.add(getResources().getText(R.string.str_list4).toString());

if(telMgr.getSimOperatorName().equals(“”)){

value.add(“无法取得”);

}else{

value.add(telMgr.getSimOperatorName());



}



/* 取得SIM卡国别 */

item.add(getResources().getText(R.string.str_list5).toString());

if(telMgr.getSimCountryIso().equals(“”)){

value.add(“无法取得”);

}else{

value.add(telMgr.getSimCountryIso());



}
java代码: /*取得SIM卡的网络类型*/



item.add(getResources().getText(R.string.str_list6).toString());



if(telMgr.getPhoneType() == telMgr.PHONE_TYPE_CDMA){



value.add(“SIM的类型是CDMA”);



}else if(telMgr.getPhoneType() == telMgr.PHONE_TYPE_GSM){



value.add(“SIM的类型是GSM”);



}else if(telMgr.getPhoneType() == telMgr.PHONE_TYPE_NONE){



value.add(“SIM的类型是NONE”);



}else{



value.add(“无法取得”);



}



/*取得SIM卡驱动的ID号*/

item.add(getResources().getText(R.string.str_list7).toString());



if(telMgr.getDeviceId().equals(“”)){



value.add(“无法取得”);



}else{



value.add(telMgr.getDeviceId());



}



/*取得SIM卡号码/手机号码*/

item.add(getResources().getText(R.string.str_list8).toString());



if(telMgr.getLine1Number().equals(“”)){



value.add(“无法取得”);



}else{



value.add(telMgr.getLine1Number());



}



/*取得SIM卡CDMA基站的识别ID*/

item.add(getResources().getText(R.string.str_list9).toString());



if(telMgr.getCellLocation() == null){



value.add(“无法取得”);



}else{



value.add(String.valueOf(((CdmaCellLocation) telMgr.getCellLocation()).getBaseStationId()));



}



/*取得SIM卡CDMA基站的地理坐标*/

item.add(getResources().getText(R.string.str_list10).toString());



if(telMgr.getCellLocation() == null){



value.add(“无法取得”);



}else{



value.add(“经度:” +String.valueOf(((CdmaCellLocation) telMgr.getCellLocation()).getBaseStationLongitude())



+” “+“纬度:” + String.valueOf(((CdmaCellLocation) telMgr.getCellLocation()).getBaseStationLatitude()));



}



/* 使用自定义的MyAdapter来将数据传入ListActivity */

setListAdapter(new MyAdapter(this,item,value));

}



}
/*

* Wapdroid - Android Location based Wifi Manager

* Copyright (C) 2009 Bryan Emmanuel

*

* This program is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.



* You should have received a copy of the GNU General Public License

* along with this program. If not, see <http://www.gnu.org/licenses/>.

*

* Bryan Emmanuel piusvelte@gmail.com

*/



package eoe.demo;



import java.util.List;



import android.app.AlarmManager;

import android.app.Notification;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.app.Service;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.content.IntentFilter;

import android.content.SharedPreferences;

import android.net.NetworkInfo;

import android.net.wifi.WifiManager;

import android.os.BatteryManager;

import android.os.IBinder;

import android.os.RemoteException;

import android.telephony.CellLocation;

import android.telephony.NeighboringCellInfo;

import android.telephony.PhoneStateListener;

import android.telephony.SignalStrength;

import android.telephony.TelephonyManager;

import android.telephony.gsm.GsmCellLocation;

import android.util.Log;



public class WapdroidService extends Service {

private static int NOTIFY_ID = 1;

public static final String WAKE_SERVICE = "com.piusvelte.wapdroid.WAKE_SERVICE";

private WapdroidDbAdapter mDbHelper;

private NotificationManager mNotificationManager;

private TelephonyManager mTeleManager;

private String mSsid = "", mBssid = "", mOperator = "", mOperatorName = "", mMcc = "";

private List<NeighboringCellInfo> mNeighboringCells;

private WifiManager mWifiManager;

private int mCid = WapdroidDbAdapter.UNKNOWN_CID, mLac = WapdroidDbAdapter.UNKNOWN_CID, mRssi = 99, mWifiState, mInterval, mPhoneType = TelephonyManager.PHONE_TYPE_NONE, mNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;

private boolean mWifiIsEnabled, mNotify, mVibrate, mLed, mRingtone, mBatteryOverride, mBatteryLock = true;

private AlarmManager mAlarmMgr;

private PendingIntent mPendingIntent;

private IWapdroidUI mWapdroidUI;

private boolean mControlWifi = true;

private static final String TAG = "Wapdroid";

private double mBatteryPercentage = 100.0, mBatteryRemaining;



private final IWapdroidService.Stub mWapdroidService = new IWapdroidService.Stub() {

public void updatePreferences(int interval, boolean notify,

boolean vibrate, boolean led, boolean ringtone, boolean batteryOverride, int batteryPercentage)

throws RemoteException {

mInterval = interval;

if (mNotify && !notify) {

mNotificationManager.cancel(NOTIFY_ID);

mNotificationManager = null;}

else if (!mNotify && notify) {

mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

CharSequence contentTitle = getString(mWifiIsEnabled ? R.string.label_enabled : R.string.label_disabled);

Notification notification = new Notification((mWifiIsEnabled ? R.drawable.scanning : R.drawable.status), contentTitle, System.currentTimeMillis());

PendingIntent contentIntent = PendingIntent.getActivity(getBaseContext(), 0, new Intent(getBaseContext(), WapdroidService.class), 0);

notification.setLatestEventInfo(getBaseContext(), contentTitle, getString(R.string.app_name), contentIntent);

mNotificationManager.notify(NOTIFY_ID, notification);}

mNotify = notify;

mVibrate = vibrate;

mLed = led;

mRingtone = ringtone;

mBatteryOverride = batteryOverride;

mBatteryPercentage = batteryPercentage;}

public void setCallback(IBinder mWapdroidUIBinder)

throws RemoteException {

if (mWapdroidUIBinder != null) {

Log.v(TAG, "setCallback, enable wifi control");

mControlWifi = true;

mWapdroidUI = IWapdroidUI.Stub.asInterface(mWapdroidUIBinder);

if ((mWapdroidUI != null) && (mCid != WapdroidDbAdapter.UNKNOWN_CID)) {

try {

String cells = "'" + Integer.toString(mCid) + "'";

if (!mNeighboringCells.isEmpty()) {

for (NeighboringCellInfo n : mNeighboringCells) cells += ",'" + Integer.toString(n.getCid()) + "'";}

mWapdroidUI.setOperator(mOperatorName, mMcc, mOperator);

mWapdroidUI.setCellInfo(Integer.toString(mCid), Integer.toString(mLac));

mWapdroidUI.setWifiInfo(mWifiState, mSsid, mBssid);

mWapdroidUI.setSignalStrength(mRssi);

mWapdroidUI.setCells(cells);

mWapdroidUI.setBattery(mBatteryRemaining);}

catch (RemoteException e) {}}}}

public void suspendWifiControl() throws RemoteException {

Log.v(TAG, "running wifi settings, disable wifi control");

mControlWifi = false;

}

};
回复

使用道具 举报

该用户从未签到

发表于 2011-10-22 12:30:51 | 显示全部楼层

Re:[实例教程]Android

找了好久的例子,谢谢
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2011-10-22 12:30:57 | 显示全部楼层

Re:[实例教程]Android

找了好久的例子,谢谢
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2011-10-22 12:31:07 | 显示全部楼层

Re:[实例教程]Android

chino这个SIM卡中有没有他的短信中心码呢?!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

GMT+8, 2024-12-23 09:41 , Processed in 1.690789 second(s), 45 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表