欢迎来到代码驿站!

Android代码

当前位置:首页 > 移动开发 > Android代码

android监控sim卡有没有服务示例(sim卡管理)

时间:2022-11-04 09:53:50|栏目:Android代码|点击:


复制代码 代码如下:

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);
}
}
}
}

上一篇:Flutter使用AnimatedOpacity实现图片渐现动画

栏    目:Android代码

下一篇:Android如何使用GestureDetector进行手势检测详解

本文标题:android监控sim卡有没有服务示例(sim卡管理)

本文地址:http://www.codeinn.net/misctech/218155.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有