struts2單個文件上傳的兩種完成方法。本站提示廣大學習愛好者:(struts2單個文件上傳的兩種完成方法)文章只能為提供參考,不一定能成為您想要的結果。以下是struts2單個文件上傳的兩種完成方法正文
平日來講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 該辦法就會觸發,便可以停止響應的處置。