//监听类
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
mPhone.listen(mPhoneStateListener[i], PhoneStateListener.LISTEN_SERVICE_STATE);
}
}
//取消监听
private void unregisterPhoneListener() {
mSub = MSimTelephonyManager.getDefault().getPhoneCount();
for (int i = 0; i
mPhone.listen(mPhoneStateListener[i], PhoneStateListener.LISTEN_NONE);
}
}
}
}