捕获Intent.ACTION_MEDIA_BUTTON事件

发布于 2024-12-03 23:21:00 字数 976 浏览 1 评论 0原文

我正在开发一个 Android 音频应用程序。现在,我正在捕捉 并成功播放音频,我想添加一个新功能,通过蓝牙耳机捕获和播放。

我一直在阅读有关内容,似乎我必须管理 ACTION_MEDIA_BUTTON 事件:

Java文件:

....

public class audioBroadcastReceiver extends BroadcastReceiver 
{
    public void onReceive(Context context, Intent intent) 
    {
        if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) 
        {
            Log.d("","@@@@ WORKS" );
        }
        else
    {
    Log.d("","@@@@ ????" );                      
}
....

xml文件

....
<receiver android:name="audioBroadcastReceiver">
    <intent-filter>     
        <action android:name="android.intent.action.MEDIA_BUTTON">
        </action>
    </intent-filter>
</receiver>
<uses-permission android:name="android.permission.BLUETOOTH" />

但是什么也没发生,所以,有人可能会给我一个例子或想法:

1°知道蓝牙何时连接。

2° 通过蓝牙耳机路由音频数据包。

谢谢!

I'm developing a Android audio application. Now, I'm capturing
and playing audio with sucess and I want to add a new feature, the capture and playing through bluetooh headset.

I have been reading about that, and seems that I must manage the ACTION_MEDIA_BUTTON
event:

Java file:

....

public class audioBroadcastReceiver extends BroadcastReceiver 
{
    public void onReceive(Context context, Intent intent) 
    {
        if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) 
        {
            Log.d("","@@@@ WORKS" );
        }
        else
    {
    Log.d("","@@@@ ????" );                      
}
....

xml file

....
<receiver android:name="audioBroadcastReceiver">
    <intent-filter>     
        <action android:name="android.intent.action.MEDIA_BUTTON">
        </action>
    </intent-filter>
</receiver>
<uses-permission android:name="android.permission.BLUETOOTH" />

But nothing happens, so, somebody may give me a example or a idea for:

1º Know when the bluetooh has been connected.

2º Routed the audio packets through bluetooh headset.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巴黎夜雨 2024-12-10 23:21:00

您需要 bluetoothAdapter 方法。
蓝牙适配器 blueT = 蓝牙适配器.getDefaultAdapter();

// create broadcast receiver
BroadcastReceiver blueReceiver = new BroadcastReceiver(){
// todo switch states to turn on or off or check is on
// check is on is something like this:
case (blueT.STATE_ON) : {
 // do something with it
}

if(blueT.isEnabled()){
do something
}

You need the bluetoothAdapter method.
BluetoothAdapter blueT = BluetoothAdapter.getDefaulAdapter();

// create broadcast receiver
BroadcastReceiver blueReceiver = new BroadcastReceiver(){
// todo switch states to turn on or off or check is on
// check is on is something like this:
case (blueT.STATE_ON) : {
 // do something with it
}

if(blueT.isEnabled()){
do something
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文