2013-11-28 70 views

回答

0

此代碼適用於我。希望它能幫到你

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.telephony.TelephonyManager; 
import android.util.Log; 

public class CallStateReceiver extends BroadcastReceiver { 

private final String LOG_TAG = "CallStateReceiver"; 

public static String prevState = TelephonyManager.EXTRA_STATE_IDLE; 

@Override 
public void onReceive(Context context, Intent intent) { 

    Bundle bundle = intent.getExtras(); 
    if (bundle == null) { 
     return; 
    } 

    String state = bundle.getString(TelephonyManager.EXTRA_STATE); 

    if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE) 
      && !prevState.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)) { 

     Log.i(this.LOG_TAG, "Call ended")); 
    } 

    prevState = state; 
} 
} 
0

一旦通話結束手機狀態應該是TelephonyManager.CALL_STATE_IDLE

0

使用PhoneStateListener來接收變化的通知中指定的電話狀態。

超越控制onCallStateChanged (int state, String incomingNumber)並檢查state參數

if (state == CALL_STATE_IDLE) { 
    //this is current Phone state at the time of call end, handle call end here 
} 

三種狀態指示如下:

CALL_STATE_IDLE - >設備通話狀態:無活動。
CALL_STATE_OFFHOOK - >設備呼叫狀態:摘機。至少存在一個呼叫正在撥號,處於活動狀態或處於保持狀態,並且沒有呼叫正在振鈴或等待。
CALL_STATE_RINGING - >設備呼叫狀態:振鈴。一個新的電話到達 並且正在響鈴或等待。在後一種情況下,另一個呼叫已經是 有效。

欲瞭解更多信息,請參閱documentation

0
TelephonyManager.CALL_STATE_IDLE #When a call end, no matter what, call received by user or not 

TelephonyManager.CALL_STATE_OFFHOOK #when user receive a call 

TelephonyManager.CALL_STATE_RINGING #when phone ring (incoming call)