您的位置:首页 > 其它

获取手机号码/判断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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: