简体   繁体   English

打开来电Android中的扬声器

[英]Turn ON speaker in incoming call Android

I would like to turn on the speaker and set it to maximum volume. 我想打开扬声器并将其设置为最大音量。 In my PhoneStateListener I'm intercepting the incoming call, and it works fine for any incoming/outgoing call. 在我的PhoneStateListener中,我正在拦截来电,它适用于任何传入/传出呼叫。

The thing is that I want to turn on this feature only for two specific incoming numbers. 问题是我只想为两个特定的传入号码启用此功能。

This is my code: 这是我的代码:

    case TelephonyManager.CALL_STATE_OFFHOOK:
        if (incomingNumber.equals( strRegisterNumber1) || incomingNumber.equals( strRegisterNumber2))
        {
            AudioManager audioManager = (AudioManager) contextMember.getSystemService(Context.AUDIO_SERVICE);
            audioManager.setSpeakerphoneOn(true);
            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);

        }
        break;

Without the if statement it works fine but int his case the speaker stays off. 没有if语句它可以正常工作,但在他的情况下,扬声器保持关闭状态。

Please advise what I'm doing wrong or how to achieve my goal? 请告诉我我做错了什么或如何实现我的目标?

Thank you for your help. 谢谢您的帮助。

Instaed of Instaed of

incomingNumber.equals( strRegisterNumber1) || incomingNumber.equals( strRegisterNumber2) 

use 采用

incomingNumber.contains( strRegisterNumber1) || incomingNumber.contains( strRegisterNumber2)

Because the incoming number might have + with country code or 00 with country code. 因为传入的号码可能带有国家/地区代码+或带国家/地区代码的00 So you just have to check if the incoming call's number contains the required number. 因此,您只需检查来电号码是否包含所需号码。

Hope it helps... 希望能帮助到你...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM