編輯:關於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);
}
}
}
}
概述用Time和Calendar獲取系統當前時間(年月日時分秒周幾)效果圖源碼:import android.app.Activity; import android.o
本文實例講述了Android控件之Gallery用法。分享給大家供大家參考。具體如下:Gallery組件主要用於橫向顯示圖像列表,不過按常規做法。Gallery組件只能有
先上圖 LEDView效果如圖所示。 之前看到一篇博客使用兩個TextView實現了該效果,於是我想用自定義控件的方式實現一個LEDView,使用時即可直接使用該控件。
本文為那些不錯的Android開源項目第三篇——優秀項目篇,主要介紹那些還不錯的完整Android項目。記錄的項目主要依據是項目有意思或項目分層規