背景 :
开发应用程序,使Android手机A2DP接收器 .
BlueDroid堆栈支持A2DP接收器,但默认情况下禁用它 . Modified source code to enable A2DP . Android手机被视为HeadsFree设备,可以连接 .
问题:
I can't hear sound.
试过:
A2dpSinkStateMachine类负责将android作为 A2dpSink
. 其中一个状态是Connected,它有方法broadcastAudioState,在音频启动/停止流式传输时调用 . (line 579)
broadcastAudioState
使用操作发送广播 BluetoothA2dpSink.ACTION_PLAYING_STATE_CHANGED
(line 696)并写入日志A2DP Playing state....))
注册广播接收器
- 尝试通过
manifest.xml
文件
<receiver android:name=".PlayingStateChangeBroadcastReceiver">
<intent-filter>
<action android:name="android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED" />
</intent-filter>
</receiver>
- 动态也是
Intent intent =
registerReceiver(mReceiver, new IntentFilter(BluetoothA2dp.ACTION_PLAYING_STATE_CHANGED));
- 动态授权
Intent intent =
registerReceiver(
mReceiver,
new IntentFilter(BluetoothA2dp.ACTION_PLAYING_STATE_CHANGED),
"android.permission.BLUETOOTH",
new Handler(Looper.getMainLooper()));
永远不会调用 onReceive
方法 .
另外:
-
动态注册时
registerReceiver
返回null
. -
在
Android monitor
窗口内,我看到log A2DP Playing state ...,意思是发送广播 . -
android.bluetooth.a2dp-sink.profile.action.PLAYING_STATE_CHANGED
在platform/frameworks/base/core/res/AndroidManifest.xml文件中声明为<protected-broadcast>
任何想法,如何解决?
谢谢