代码如下:public class UniteqService {public static final String LOG_TAG = "UniteqService";p
代码如下:
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);
}
}
}
}
--结束END--
本文标题: android监控sim卡有没有服务示例(sim卡管理)
本文链接: https://lsjlt.com/news/27269.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0