我正在使用以下广播接收器来检索传出电话号码。
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
mIntent = intent;
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int events = PhoneStateListener.LISTEN_CALL_STATE;
tm.listen(phoneStateListener, events);
}
private final PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
dialingNumber = mIntent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(mContext, "Local Call Number- " + dialingNumber,Toast.LENGTH_SHORT).show();
break;
}
return;
}
Log.i(">>>Broadcast", "onCallStateChanged " + callState);
super.onCallStateChanged(state, incomingNumber);
}
};
有时它返回 null 或我之前拨打的号码。是否有另一种方法来检索当前呼叫的呼入/呼出电话号码?