android監(jiān)控sim卡有沒有服務(wù)示例(sim卡管理)
public class UniteqService {
public static final String LOG_TAG = "UniteqService";
public boolean DEBUG = true;
private boolean hasService = false;//是否有服務(wù)
private PhoneStateListener[] mPhoneStateListener;//監(jiān)聽雙卡
private TelephonyManager mPhone;
//監(jiān)聽類
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;
}
//注冊監(jiān)聽
private void registerPhoneListener() {
//獲取卡號數(shù),MSimTelephonyManager 這個類API沒有開放,可以通過編譯源碼
//得到frameworks.jar包并導(dǎo)入你的工程, 然后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);
}
}
//取消監(jiān)聽
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);
}
}
}
}
相關(guān)文章
Android?Studio中如何修改APP圖標和APP名稱
這篇文章主要介紹了Android?Studio中如何修改APP圖標和APP名稱,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-11-11android?Service基礎(chǔ)(啟動服務(wù)與綁定服務(wù))
大家好,本篇文章主要講的是android?Service基礎(chǔ)(啟動服務(wù)與綁定服務(wù)),感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12Flutter開發(fā)之Widget自定義總結(jié)
這篇文章主要給大家介紹了關(guān)于Flutter開發(fā)中Widget自定義的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用Flutter具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04Android 中LayoutInflater.inflate()方法的介紹
這篇文章主要介紹了Android 中LayoutInflater.inflate()方法的介紹的相關(guān)資料,希望通過本文大家能掌握這部分內(nèi)容,需要的朋友可以參考下2017-09-09Android開發(fā)框架之自定義ZXing二維碼掃描界面并解決取景框拉伸問題
這篇文章主要介紹了Android開發(fā)框架之自定義ZXing二維碼掃描界面并解決取景框拉伸問題的相關(guān)資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下2016-06-06詳解Android中使用Notification實現(xiàn)進度通知欄(示例三)
這篇文章主要介紹了詳解Android中使用Notification實現(xiàn)進度通知欄(示例三),具有一定的參考價值,有興趣的可以了解一下。2016-12-12