編輯:關於Android編程
通常來說Android手機沒有未接來電的監聽器,如果要實現對未接來電的處理,則需要自己編寫程序來實現。本文所述程序實例即為Android實現判斷手機未接來電及處理方法。主要分為四個步驟來進行:
1、編寫CallListener,處理手機狀態變更監聽,當狀態改變時進行處理:
package rbase.app.smshelpmate.call.listener; import java.text.MessageFormat; import rbase.app.smshelpmate.Config; import rbase.app.smshelpmate.R; import rbase.app.smshelpmate.call.enums.CallStateEnum; import rbase.app.smshelpmate.forward.ForwardManager; import rbase.app.smshelpmate.forward.enums.ForwardType; import rbase.app.smshelpmate.forward.vo.ForwardParam; import android.content.Context; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; public class CallListener extends PhoneStateListener { private static final String TAG = "sms"; private static int lastetState = TelephonyManager.CALL_STATE_IDLE; //最後的狀態 private Context context; public CallListener(Context context) { super(); this.context = context; } public void onCallStateChanged(int state, String incomingNumber) { Log.v(TAG, "CallListener call state changed : " + incomingNumber); String m = null; // 如果當前狀態為空閒,上次狀態為響鈴中的話,則認為是未接來電 if(lastetState == TelephonyManager.CALL_STATE_RINGING && state == TelephonyManager.CALL_STATE_IDLE){ sendSmgWhenMissedCall(incomingNumber); } //最後改變當前值 lastetState = state; } private void sendSmgWhenMissedCall(String incomingNumber) { //未接來電處理(發短信,發email等) } }
2、編寫CallReceiver,注冊來電廣播接收器:
package rbase.app.smshelpmate.call.service; import rbase.app.smshelpmate.Const; import rbase.app.smshelpmate.call.listener.CallListener; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; public class CallReceiver extends BroadcastReceiver{ public void onReceive(Context context, Intent intent) { Log.i("sms", "CallReceiver Start..."); TelephonyManager telephony = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); CallListener customPhoneListener = new CallListener(context); telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); Bundle bundle = intent.getExtras(); String phoneNr = bundle.getString("incoming_number"); Log.i("sms", "CallReceiver Phone Number : " + phoneNr); } }
3、在AndroidManifest.xml中的application節點下注冊電話狀態改變的廣播接收:
<manifest ...> <application ...> <receiver android:name=".call.service.CallReceiver"> <intent-filter android:priority="100"> <action android:name="android.intent.action.PHONE_STATE" /> </intent-filter> </receiver> </application> </manifest>
4、在AndroidManifest.xml中添加讀取手機狀態的權限:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
通過以上的步驟,當手機有未接來電時 sendSmgWhenMissedCall 該方法就會觸發,就可以進行相應的處理。
安裝SVN服務端安裝VisualSVN-Server,我的電腦是XP,所以安裝的VisualSVN-Server-2.5.8.msi版本。 這裡要注
面對一個項目,對於Android應用開發框架的選擇,我想過三種方案:1.使用Loader + HttpClient + GreenDao + Gson + Fragmen
AppWidget 通過內存共享進行數據通訊.原理圖如下: 1.創建一個BroadcastReceiver,繼承AppWidgetProvider. 2.在Androi
Volley簡介我們平時在開發Android應用的時候不可避免地都需要用到網絡技術,而多數情況下應用程序都會使用HTTP協議來發送和接收網絡數據。Androi