andoird拨号流程简单解析

android拨号分两种,一种经过拨号器,输入号码,然后按CALL键拨打出去,还有一种经过联系人或者通话记录拨打出去。

 

第一种方式:TwelveKeyDialer.java中的placeCall()

void placeCall() {
        final String number = mDigits.getText().toString();
        if (number == null || !TextUtils.isGraphic(number)) {
            // There is no number entered.
            playTone(ToneGenerator.TONE_PROP_NACK);
            return;
        }
        Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
                Uri.fromParts("tel", number, null));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        mDigits.getText().clear();
        finish();
    }

定一个一个ACTION_CALL_PRIVILEGED,自动匹配上OutgoingCallBroadcaster

if (Intent.ACTION_CALL_PRIVILEGED.equals(action)) {
            action = emergencyNumber
                    ? Intent.ACTION_CALL_EMERGENCY
                    : Intent.ACTION_CALL;
            intent.setAction(action);
        }

区分号码是否为紧急号码,是紧急号码的话立即起一个InCallScreen的Activity,不是的话发出广播,转发一个拨号Intent,

Intent broadcastIntent = new Intent(Intent.ACTION_NEW_OUTGOING_CALL);
        if (number != null) broadcastIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, number);
        broadcastIntent.putExtra(EXTRA_ALREADY_CALLED, callNow);
        broadcastIntent.putExtra(EXTRA_ORIGINAL_URI, intent.getData().toString());
        if (LOGV) Log.v(TAG, "Broadcasting intent " + broadcastIntent + ".");
        sendOrderedBroadcast(broadcastIntent, PERMISSION, null, null,
                             Activity.RESULT_OK, number, null);

而OutgoingReceiver接收到广播以后,才起一个InCallScreen

Intent newIntent = new Intent(Intent.ACTION_CALL, uri);
        newIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, number);
        newIntent.setClass(context, InCallScreen.class);
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        context.startActivity(newIntent);

这样,这个拨打的过程就完成了。

 

 

如果在历史通话记录界面,响应用户的click请求

protected void onListItemClick(ListView l, View v, int position, long id) {
    static final int COLUMN_INDEX_NUMBER = 4;                                           |        Intent intent = new Intent(this, CallDetailActivity.class);
                                                                                        |        intent.setData(ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, id));
    @Override                                                                           |        startActivity(intent);
    protected void onCreate(Bundle icicle) {                                            |    }
起一个CallDetailActivity,在CallDetailActivity界面,如果当前电话是空闲的,直接发一个ACTION_CALL_PRIVILEGED给OutgoingCallBroadcaster

TelephonyManager tm = (TelephonyManager)                                |
                        getSystemService(Context.TELEPHONY_SERVICE);                    |            int callType = cursor.getInt(CALL_TYPE_COLUMN_INDEX);
                if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {            |            if (!number.startsWith("+") &&
                    Intent callIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED,       |                    (callType == Calls.INCOMING_TYPE
                            Uri.fromParts("tel", mNumber, null));                       |                            || callType == Calls.MISSED_TYPE)) {
                    startActivity(callIntent);

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值