【发布时间】:2015-11-11 04:43:09
【问题描述】:
我需要在通话接通时启动计时器,但在我的情况下,它是在通话响铃时启动的,我搜索了很多,但没有得到正确的解决方案。我再次怀着希望重复这一点。至少我需要一个建议来实现这一点。
我的代码:
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
Log.d("Status", "Phone is Ringing");
} else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
Log.d("Status", "Phone is on call");
} else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
// Call Dropped or rejected
System.exit(0);
Log.d("Status", "Phone is dropped");
}
}
【问题讨论】:
标签: java android call telephonymanager phone-state-listener