2017-07-10 39 views
1

我正在开发一个应用程序,在该应用程序中,我必须播放每秒生成的通知声音从内部扬声器摇晃手机,同时我的应用程序通过(a2dp)连接到汽车的蓝牙。我必须将通知音频路由至内置扬声器,并将所有其他声音(音乐,通话,提醒等)传送至蓝牙扬声器。这可能吗?Rout向内部扬声器和所有其他(音乐,呼叫,警报)蓝牙扬声器(a2dp)的android通知声音

我研究了所有发布在堆栈上的相关问题,但似乎没有人回答它们。以下是我通过音频管理器类尝试的代码片段。

我试图航线使用音频流内置的方法

AudioManager audioManager = (AudioManager) getContext().getSystemService(AUDIO_SERVICE); 
    audioManager.setMode(AudioManager.ROUTE_EARPIECE); 
    audioManager.setSpeakerphoneOn(false); 

这对于时间将切断从蓝牙音箱流,但一旦流背后播放的所有音乐重新路由到BT喇叭,然后没有通知声音。我尝试了所有的音频管理器路由和模式,但似乎没有任何工作。 通知声音是一个MP3,并通过解析URI设置路径,这是我建立我的通知。

NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(context) 
        .setSmallIcon(R.drawable.newlogo) 
        .setLargeIcon(largeIcon) 
        .setSound(uri) 
        .setContentTitle(notificationHeading) 
        .setContentText(notificationBody) 
        .setPriority(Notification.PRIORITY_HIGH).setVibrate(v); 
    notificationManager.notify(1,mBuilder.build()); 

所以如果有这个东西是可能我更愿意把它更多的是一丝机会,任何图书馆甚至付出的,如果解决这个问题,请你分享,也是我无法根电话这个程序是将在Play商店发布。

回答

0

通过AudioTrack.java类播放发言者通知的声音并使用流AUDIO_STREAM_TTS(简称'发送低音扬声器')或AUDIO_STREAM_ENFORCED_AUDIBLE。

https://developer.android.com/reference/android/media/AudioTrack.html#AudioTrack(int,%20int,%20int,%20int,%20int,%20int)

AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user 
            * and must be routed to speaker 
            */ 
AUDIO_STREAM_TTS    = 9, /* Transmitted Through Speaker. 
            * Plays over speaker only, silent on other devices. 
            */ 
相关问题