android DTMFTwelveKeyDialer使用中的一个问题

最近发现在android 4.2中,此类在InCallScreen中实例化为成员变量mDialer,

在InCallScreen中的onResume中有如下调用:

mDialer.startDialerSession();

在InCallScreen的onPause中会调用

mDialer.stopDialerSession();


下面是这两个调用函数的实现代码:

DTMFTwelveKeyDialer.java

public void startDialerSession() {
        if (DBG) log("startDialerSession()... this = " + this);


        // see if we need to play local tones.
        if (PhoneApp.getInstance().getResources().getBoolean(R.bool.allow_local_dtmf_tones)) {
            mLocalToneEnabled = Settings.System.getInt(mInCallScreen.getContentResolver(),
                    Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1;
        } else {
            mLocalToneEnabled = false;
        }
        if (DBG) log("- startDialerSession: mLocalToneEnabled = " + mLocalToneEnabled);


        // create the tone generator
        // if the mToneGenerator creation fails, just continue without it.  It is
        // a local audio signal, and is not as important as the dtmf tone itself.
        if (mLocalToneEnabled) {
            synchronized (mToneGeneratorLock) {
                if (mToneGenerator == null) {
                    try {
                        mToneGenerator = new ToneGenerator(AudioManager.STREAM_DTMF, 80);
                    } catch (RuntimeException e) {
                        if (DBG) log("Exception caught while creating local tone generator: " + e);
                        mToneGenerator = null;
                    }
                }
            }
        }
    }


    public void stopDialerSession() {
        // release the tone generator.
        synchronized (mToneGeneratorLock) {
            if (mToneGenerator != null) {
                mToneGenerator.release();
                mToneGenerator = null;

            }
        }
    }

这两个方法一个创建了ToneGenerator对象,一个释放了此对象。

也就是在InCallScreen的onResume创建,在InCallScreen的onPause释放此对象。

在打电话过程中,只要将手机放到耳朵边就会黑屏,这是android的特性,

这个黑屏会导致调用InCallScreen 执行onPause,这样就会释放ToneGenerator对象,

导致, DTMFTwelveKeyDialer不能正常的响按键音,这会导致在将手机放到耳朵旁

(打电话时如果不用耳机外放的话人类都这样),InCallScreen执行handlePostOnDialChars

方法异常,例如:

拨号时先输入10086然后菜单选择添加两秒钟暂停,接着输入数字,然后拨打电话,

正常情况下接通后,会听到几声按键音(两秒钟暂停后面有几个数字就向几下)。但是在

上面的代码流程中,如果在黑屏后执行了onPause就会导致后续handlePostOnDialChars

调用mDialer.startLocalToneIfNeeded(ch);无法发出按键音。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值