1

我有一个应用程序在接收广播时显示祝酒词,并且动作等于 BluetoothAdapter.ACTION_STATE_CHANGED,一切正常,但这里的问题是我想在蓝牙打开但从蓝牙按钮激活蓝牙时做一些事情启动器似乎广播迟到或我的应用程序接收迟到或类似的东西,因为当我从其他应用程序启动蓝牙时,接收器工作正常且准时。

有什么问题有什么建议吗?我在清单中注册了接收器。

并且似乎有时会无限循环,因为我有两个 toast 来显示 bluetoothAdapter.ACTION_STATE_CHANGED 并且它无限显示

知道为什么会发生这件事和以前的事情吗?

接收者:

public class Receivers extends BroadcastReceiver {

protected static AlertObject BTTurningOn = new AlertObject();

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    final String action = intent.getAction();


    this.context=context;


    if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
        final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                                             BluetoothAdapter.ERROR);




        if(state == BluetoothAdapter.STATE_TURNING_ON && BTTurningOn.Activated == true)
        {
            Alert(BTTurningOn);
        }






    }


}

BTTurningOn 只是一个带有一些布尔变量的对象,用于知道是否参加广播消息

这是清单的重要部分:

<receiver android:name=".Receivers">
    <intent-filter>
        <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
</intent-filter>
</receiver>

当我从我的其他应用程序或从调整/无线连接启动蓝牙时,它工作得很好,但是当我从启动器的图标或出现通知的上栏启动它时它不起作用,我使用的是 GO Launcher EX 版本 2.76

我的另一个应用程序从该应用程序未获得的站点上获得广播并且效果很好,但区别仅在于我注册接收器的位置,该应用程序在 MAnifest 中,而其他应用程序在一个 Activity 上

4

1 回答 1

0

答案是:我在清单中没有蓝牙权限,但这有点奇怪,因为它在来自 Launcher 时没有收到广播消息,但实际上应用程序在来自我的其他应用程序时收到了它们

于 2012-07-30T17:44:44.690 回答