android监控sim卡有没有服务示例(sim卡管理)
public class uniteqservice {
public static final string log_tag = "uniteqservice";
public boolean debug = true;
private boolean hasservice = false;//是否有服务
private phonestatelistener[] mphonestatelistener;//监听双卡
private telephonymanager mphone;
//监听类
private phonestatelistener getphonestatelistener(final int sub) {
phonestatelistener sphonestatelistener = new phonestatelistener(sub) {
@override
public void onservicestatechanged(servicestate servicestate) {
// todo auto-generated method stub
if (servicestate != null) {
if (servicestate.getstate() == servicestate.state_in_service) {
hasservice = true;
} else {
hasservice = false;
}
} else {
if (debug) log.d(tag, "no service state...may be the balance is not enough" + sub);
}
super.onservicestatechanged(servicestate);
}
};
return sphonestatelistener;
}
//注册监听
private void registerphonelistener() {
//获取卡号数,msimtelephonymanager 这个类api没有开放,可以通过编译源码
//得到frameworks.jar包并导入你的工程, 然后import android.telephony.msimtelephonymanager;
msub = msimtelephonymanager.getdefault().getphonecount();
mphonestatelistener = new phonestatelistener[msub];
for (int i = 0; i < msub; i++) {
mphonestatelistener[i] = getphonestatelistener(i);
mphone.listen(mphonestatelistener[i], phonestatelistener.listen_service_state);
}
}
//取消监听
private void unregisterphonelistener() {
msub = msimtelephonymanager.getdefault().getphonecount();
for (int i = 0; i < msub; i++) {
if(mphonestatelistener[i] != null){
mphone.listen(mphonestatelistener[i], phonestatelistener.listen_none);
}
}
}
}
上一篇: 蛹虫草的功效与作用这么多,给你介绍一下
下一篇: 上海黄鱼煨面你爱吃吗,告诉你独家做法