获取手机号码/判断Sim卡状态
2012-08-05 18:47
483 查看
/**
* 获取手机中的电话号码
* @param Activity
*/
public void getName(Activity activity) {
Cursor cursor = getContentResolver().query(People.CONTENT_URI, null,
null, null, null);
while (cursor.moveToNext()) {
// 取得联系人名字
int nameFieldColumnIndex = cursor.getColumnIndex(People.NAME);
String contactName = cursor.getString(nameFieldColumnIndex);
// 取得电话号码
int numberFieldColumnIndex = cursor.getColumnIndex(People.NUMBER);
String userNumber = cursor.getString(numberFieldColumnIndex);
if (contactName != null && userNumber != null) {
ContactsItem item = new ContactsItem();
item.setContact_name(contactName);
item.setContact_number(userNumber);
allContactsList.add(item);
}
}
cursor.close();
}
/**
* 获取SIM卡中的电话号码
* @param Activity
*/
public void SimQuery(Activity activity) {
Uri uri = Uri.parse("content://icc/adn");
Cursor cursor = activity.getContentResolver().query(uri, null, null,null, null);
while (cursor.moveToNext()) {
String name = null;
String phoneNumber = null;
name = cursor.getString(cursor.getColumnIndex(People.NAME));
phoneNumber = cursor.getString(cursor.getColumnIndex(People.NUMBER));
if(!name.equals("")&&!phoneNumber.equals("")){
ContactsItem item = new ContactsItem();
item.setContact_name(name);
item.setContact_number(phoneNumber);
allContactsList.add(item);
}
}
}
/**
* 判断SIM卡的状态
*/
private void isSimExist(){
String mString = "";
TelephonyManager mTelephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
int simState = mTelephonyManager.getSimState();
switch (simState) {
case TelephonyManager.SIM_STATE_ABSENT:
mString = "没有可用的SIM卡,请插入SIM卡!";
break;
case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
mString = "需要NetworkPIN解锁";
break;
case TelephonyManager.SIM_STATE_PIN_REQUIRED:
mString = "需要PIN解锁";
break;
case TelephonyManager.SIM_STATE_PUK_REQUIRED:
mString = "需要PUN解锁";
break;
case TelephonyManager.SIM_STATE_READY:
mString = "良好";
break;
case TelephonyManager.SIM_STATE_UNKNOWN:
mString = "未知状态";
break;
}
Toast.makeText(AddContacts.this, mString, Toast.LENGTH_SHORT).show();
}
public class ContactsItem {
private String contact_id;//联系人Id
private String contact_name;//联系人姓名
private String contact_number;//联系人号码
public String getContact_id() {
return contact_id;
}
public void setContact_id(String contact_id) {
this.contact_id = contact_id;
}
public String getContact_name() {
return contact_name;
}
public void setContact_name(String contact_name) {
this.contact_name = contact_name;
}
public String getContact_number() {
return contact_number;
}
public void setContact_number(String contact_number) {
this.contact_number = contact_number;
}
}
* 获取手机中的电话号码
* @param Activity
*/
public void getName(Activity activity) {
Cursor cursor = getContentResolver().query(People.CONTENT_URI, null,
null, null, null);
while (cursor.moveToNext()) {
// 取得联系人名字
int nameFieldColumnIndex = cursor.getColumnIndex(People.NAME);
String contactName = cursor.getString(nameFieldColumnIndex);
// 取得电话号码
int numberFieldColumnIndex = cursor.getColumnIndex(People.NUMBER);
String userNumber = cursor.getString(numberFieldColumnIndex);
if (contactName != null && userNumber != null) {
ContactsItem item = new ContactsItem();
item.setContact_name(contactName);
item.setContact_number(userNumber);
allContactsList.add(item);
}
}
cursor.close();
}
/**
* 获取SIM卡中的电话号码
* @param Activity
*/
public void SimQuery(Activity activity) {
Uri uri = Uri.parse("content://icc/adn");
Cursor cursor = activity.getContentResolver().query(uri, null, null,null, null);
while (cursor.moveToNext()) {
String name = null;
String phoneNumber = null;
name = cursor.getString(cursor.getColumnIndex(People.NAME));
phoneNumber = cursor.getString(cursor.getColumnIndex(People.NUMBER));
if(!name.equals("")&&!phoneNumber.equals("")){
ContactsItem item = new ContactsItem();
item.setContact_name(name);
item.setContact_number(phoneNumber);
allContactsList.add(item);
}
}
}
/**
* 判断SIM卡的状态
*/
private void isSimExist(){
String mString = "";
TelephonyManager mTelephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
int simState = mTelephonyManager.getSimState();
switch (simState) {
case TelephonyManager.SIM_STATE_ABSENT:
mString = "没有可用的SIM卡,请插入SIM卡!";
break;
case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
mString = "需要NetworkPIN解锁";
break;
case TelephonyManager.SIM_STATE_PIN_REQUIRED:
mString = "需要PIN解锁";
break;
case TelephonyManager.SIM_STATE_PUK_REQUIRED:
mString = "需要PUN解锁";
break;
case TelephonyManager.SIM_STATE_READY:
mString = "良好";
break;
case TelephonyManager.SIM_STATE_UNKNOWN:
mString = "未知状态";
break;
}
Toast.makeText(AddContacts.this, mString, Toast.LENGTH_SHORT).show();
}
public class ContactsItem {
private String contact_id;//联系人Id
private String contact_name;//联系人姓名
private String contact_number;//联系人号码
public String getContact_id() {
return contact_id;
}
public void setContact_id(String contact_id) {
this.contact_id = contact_id;
}
public String getContact_name() {
return contact_name;
}
public void setContact_name(String contact_name) {
this.contact_name = contact_name;
}
public String getContact_number() {
return contact_number;
}
public void setContact_number(String contact_number) {
this.contact_number = contact_number;
}
}
相关文章推荐
- 获取手机sim卡的属性号码
- Android -- 程序判断手机ROOT状态,获取ROOT权限
- TelephonyManager类:Android手机及Sim卡状态的获取
- 获取Android手机中SIM卡状态
- Android获取和判断当前手机状态和信息
- Android获取和判断当前手机状态和信息
- TelephonyManager类:Android手机及Sim卡状态的获取
- Android -- 程序判断手机ROOT状态,获取ROOT权限
- Android获取手机SIM卡状态
- 程序判断手机ROOT状态,获取ROOT权限
- android,sim卡,TelephonyManager,手机SIM卡状态的获取
- android 手机及Sim卡状态的获取
- 判断SIM卡状态,获取SIM卡信息
- TelephonyManager类:Android手机及Sim卡状态的获取
- Android本机号码及Sim卡状态的获取
- 获取和判断当前手机状态和信息
- TelephonyManager类:Android手机及Sim卡状态的获取
- android获取手机的所有通讯录的号码和sim卡号码
- Android_程序判断手机ROOT状态,获取ROOT权限
- android sim卡 TelephonyManager类:Android手机及Sim卡状态的获取