取指拨号码同时呼吁。 [英] Fetch dial number while calling.

查看:106
本文介绍了取指拨号码同时呼吁。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在键盘,当我preSS呼叫按钮的电话进行呼叫前后面输入任何数字,我想在logcat中的拨号号码。

When I enter any number in keypad and after when I press call button before the phone make call, I want to get that dial number in logcat.

见下面的图片进行了解。

See below Image for understand.

我能获得多少的呼叫,如果是的话那么我哪有?

Can I get the number at the time of calling, if yes then How can I?

推荐答案

嘿,我终于得到了该解决方案.. 这样,你也可以得到。

Hey Finally i got solution for that.. like this you can also get that.

您必须使用 ITelephony.aidl 文件,如下所示:

You have to use ITelephony.aidl file Like this:

package com.android.internal.telephony;

import android.os.Bundle;
        interface ITelephony {
        boolean endCall();
        void dial(String number);
        void answerRingingCall();
        void abortCall();
    }

OutgoingCallReceiver

public class OutgoingCallReceiver extends BroadcastReceiver {

    Context context = null;
    private static final String TAG = "Phone call";
    private ITelephony telephonyService;

    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();

        if (null == bundle)
            return;

        String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        Log.i("OutgoingCallReceiver", phonenumber);
        Log.i("OutgoingCallReceiver", bundle.toString());

        String info = "Detect Calls sample application\nOutgoing number: "+ phonenumber;
        /* System.out.println("value id:"+info); */
        Toast.makeText(context, info, Toast.LENGTH_LONG).show();

        TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        try {
            Class c = Class.forName(telephony.getClass().getName());
            Method m = c.getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            /*
             * com.android.internal.telephony.ITelephony telephonyService =
             * (ITelephony) m.invoke(tm);
             */
            telephonyService = (ITelephony) m.invoke(telephony);
            telephonyService.answerRingingCall();
            telephonyService.endCall();
            telephonyService.dial(null);
            telephonyService.abortCall();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

如果你想获得 IncomingCallReceiver 那么这样你可以:

public class IncomingCallReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
            Bundle bundle = intent.getExtras();

            if(null == bundle)
                    return;

            Log.i("IncomingCallReceiver",bundle.toString());
            String state = bundle.getString(TelephonyManager.EXTRA_STATE);
            Log.i("IncomingCallReceiver","State: "+ state);
            if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
            {
                    String phonenumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
                    Log.i("IncomingCallReceiver","Incomng Number: " + phonenumber);
                    System.out.println("Coming in Incoming Number"+phonenumber);
                    String info = "Detect Calls sample application\nIncoming number: " + phonenumber;
                    Toast.makeText(context, info, Toast.LENGTH_LONG).show();
            }
    }

}

和雅家伙不要忘记添加权限在 AndroidManifest 文件:

And ya Guys don't forget to add Permission in AndroidManifest file :

 <receiver android:name="com.varma.samples.detectcalls.receivers.OutgoingCallReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.varma.samples.detectcalls.receivers.IncomingCallReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>

    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.CALL_PRIVILEGED" />

这篇关于取指拨号码同时呼吁。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆