gpt4 book ai didi

android - 订阅附近的服务 - MessageListener 从未调用过

转载 作者:太空狗 更新时间:2023-10-29 13:53:17 26 4
gpt4 key购买 nike

订阅附近的服务总是声明订阅成功但 MessageListener 从未调用过:

主 Activity .java

SubscribeOptions options = new SubscribeOptions.Builder()
.setStrategy(Strategy.BLE_ONLY).build();
Nearby.Messages.subscribe(mGoogleApiClient, getPendingIntent(), options);

private PendingIntent getPendingIntent() {
return PendingIntent.getBroadcast(this, 0, new Intent(this, BeaconMessageReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
}

BeaconMessageReceiver.java

public class BeaconMessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Nearby.Messages.handleIntent(intent, new MessageListener() {
@Override
public void onFound(Message message) {
Log.i("BeaconMessageReceiver", "Found message via PendingIntent: " + message);
}

@Override
public void onLost(Message message) {
Log.i("BeaconMessageReceiver", "Lost message via PendingIntent: " + message);
}
});
}
}

最佳答案

您需要将以下内容添加到您的 list 中

    <receiver android:name="BeaconMessageReceiver" >
</receiver>

关于android - 订阅附近的服务 - MessageListener 从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42945473/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com