2011-11-22 121 views
2

我已經註冊了incomingCall廣播接收器,它工作正常,但是當呼叫建立(或拒絕)時我需要接收器。當用戶按下「應答」或「拒絕」呼叫時,我實際需要的是通知我。來電廣播接收器

回答

8

你可以重寫你的廣播接收器的方法的onReceive如下

public void onReceive(Context context, Intent intent) { 

    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); 

    if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { 
     //Phone is ringing 
    } else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { 
     //Call received 
    } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) { 
     //Call Dropped or rejected 
    } 
} 
+0

看一看也http://stackoverflow.com/questions/5486793/ansroid-listen-incoming-calls-through-broadcastreceiver-without -phonestateint –

+0

)在第4行中錯過 –