Microsoft Band:显示来自Broadcast Receiver的频段通知

时间:2015-10-05 11:07:35

标签: android broadcastreceiver microsoft-band

我正在尝试在收到带有Android应用的Google云消息时在MS频段上显示提醒。我正在使用Azure通知中心发送和响应消息。收到消息后,我想向乐队发送通知。

我目前遇到的问题是,当我在NotificationHandler中检查band连接时,抛出以下异常:

  

不允许BroadcastReceiver组件绑定到服务

有问题的代码如下:

if (client == null) {
        BandInfo[] devices = BandClientManager.getInstance().getPairedBands();
        if (devices.length == 0) {
            Log.i(TAG, "Band isn't paired with your phone");
            return false;
        }
        client = BandClientManager.getInstance().create(ctx, devices[0]);
    } else if (ConnectionState.CONNECTED == client.getConnectionState()) {
        return true;
    }

    Log.i(TAG, "Band is connecting...");
    return ConnectionState.CONNECTED == client.connect().await();

调用client.connect().await()

时会抛出异常

我假设通知处理程序在场景中被配置为BroadcastReceiver,并且通过尝试与Band进行交互,我通过绑定到服务来破坏BroadcastReceiver的规则。

我该如何处理这种情况?当然这是一个常见的场景 - 镜像应用程序拾取的乐队通知?我想要处理这个问题的唯一方法是创建一个新的Intent服务来显示通知并从BroadcastReciever启动它,但这看起来有点笨重?

1 个答案:

答案 0 :(得分:0)

I decided to create an Intent Service which I fire up in the broadcast receiver to handle the sending of the message to the Band. This allows the receiver to respond and exit quickly and the band connection can happen in the service.

It's not really as clunky as I imagined.