0

我正在尝试说一些文字。由于某些奇怪的原因,静音 STREAM_RING 也将文本静音。我已经搜索过互联网,但我想以前没有人遇到过这个问题,所以我找不到答案。这是我的代码:

int volume=0;

    if(state == TelephonyManager.CALL_STATE_RINGING)
    {
        Toast.makeText(getApplicationContext(), "Inside", Toast.LENGTH_SHORT).show();

        if(incomingNumber != null)
        {
            volume= audioManager.getStreamVolume(AudioManager.STREAM_RING);


            audioManager.setStreamMute(AudioManager.STREAM_RING, true);
            audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, AudioManager.FLAG_ALLOW_RINGER_MODES);
            tts.speak(incomingNumber, TextToSpeech.QUEUE_FLUSH, null);

            Toast.makeText(getApplicationContext(), "speak number", Toast.LENGTH_SHORT).show();
        }


        if(state == TelephonyManager.CALL_STATE_IDLE)
        {
            audioManager.setStreamVolume(AudioManager.STREAM_RING, volume, AudioManager.FLAG_ALLOW_RINGER_MODES);
            audioManager.setStreamMute(AudioManager.STREAM_RING, false);
        }
    }
}
4

1 回答 1

1
int mRingerMode;

Toast.makeText(getApplicationContext(), "INCOMING CALL", Toast.LENGTH_SHORT).show();

if(state == TelephonyManager.CALL_STATE_RINGING)
{
    Toast.makeText(getApplicationContext(), "Inside", Toast.LENGTH_SHORT).show();

    if(incomingNumber != null)
    {
        mRingerMode = audioManager.getRingerMode();
                        audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                HashMap<String, String> myHashRender = new HashMap<String, String>();
                myHashRender.put(TextToSpeech.Engine.KEY_PARAM_STREAM, 
                        String.valueOf(AudioManager.STREAM_VOICE_CALL));
                tts.speak(incomingNumber, TextToSpeech.QUEUE_FLUSH, myHashRender);
            }
        }).start();

        Toast.makeText(getApplicationContext(), "speak number", Toast.LENGTH_SHORT).show();
    }


    if(state == TelephonyManager.CALL_STATE_IDLE)
    {
        audioManager.setRingerMode(mRingerMode);
    }
}

}

于 2013-06-30T17:46:55.687 回答