【发布时间】:2020-12-25 11:24:00
【问题描述】:
我正在我的应用程序中进行 quickblox 集成。我已经成功集成了聊天功能,而且效果很好。但是推送通知功能不起作用。我已按照以下步骤集成推送通知。
-
在 firebase 上创建一个项目。实现云消息传递并将 google JSON 集成到主项目中。
-
登录 quickblox 帐户会在推送通知中添加 google 服务器密钥。
-
关注https://docs.quickblox.com/docs/android-push-notifications 文档并在添加firebase cloude 消息后,我在menifest 文件中添加以下内容。
<meta-data android:name="com.quickblox.messages.TYPE" android:value="FCM" /> <meta-data android:name="com.quickblox.messages.SENDER_ID" android:value="@string/sender_id" /> <meta-data android:name="com.quickblox.messages.QB_ENVIRONMENT" android:value="DEVELOPMENT" />
并在清单中注册以下服务
`<service android:name="com.quickblox.messages.services.fcm.QBFcmPushListenerService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="com.quickblox.messages.services.fcm.QBFcmPushInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>`
- 我添加了自动推送通知,并在 chatActivity 的代码中实现了它
`QBSettings.getInstance().setEnablePushNotification(false); // 默认为真
boolean isEnabled = QBSettings.getInstance().isEnablePushNotification();`
-
为推送通知创建订阅
QBSubscription 订阅 = 新 QBSubscription(QBNotificationChannel.GCM); 订阅.setEnvironment(QBEnvironment.DEVELOPMENT); // 字符串设备 ID = ""; 最终 TelephonyManager mTelephony = (TelephonyManager) BottomActivity.this.getSystemService( Context.TELEPHONY_SERVICE);
deviceId = Settings.Secure.getString(BottomActivity.this.getContentResolver(), Settings.Secure.ANDROID_ID); subscription.setDeviceUdid(deviceId); subscription.setRegistrationID(registrationID); subscription.setEnvironment(QBEnvironment.DEVELOPMENT); QBPushNotifications.createSubscription(subscription); -
为推送通知注册接收器。
LocalBroadcastManager.getInstance(this).registerReceiver(pushBroadcastReceiver, new IntentFilter(Consts.ACTION_NEW_FCM_EVENT)); -
发送推送消息。
` String outMessage = messageEditText.getText().toString().trim(); QBEvent qbEvent = new QBEvent(); qbEvent.setNotificationType(QBNotificationType.PUSH); qbEvent.setEnvironment(QBEnvironment.DEVELOPMENT);
qbEvent.setMessage(outMessage); qbEvent.setPushType(QBPushType.GCM); StringifyArrayList<Integer> userIds = new StringifyArrayList<>(); userIds.add(QBSessionManager.getInstance().getSessionParameters().getUserId()); userIds.add(qbChatDialog.getRecipientId()); Log.d(TAG, "My Id: " + qbChatDialog.getRecipientId()); qbEvent.setUserIds(userIds); QBPushNotifications.createEvent(qbEvent).performAsync(new QBEntityCallback<QBEvent>() { @Override public void onSuccess(QBEvent qbEvent, Bundle bundle) { } @Override public void onError(QBResponseException e) { KeyboardUtils.hideKeyboard(messageEditText); invalidateOptionsMenu(); } });`
在完成所有步骤后,我能够成功发送消息。我可以在 quickblox 管理面板中看到一条消息,它显示已传递的消息。订阅也被创建。但我没有在我的另一部手机上收到通知。但是,当我尝试使用 firebase cloud 发送强制消息时,我能够收到在 firebase 上键入的消息。
谁能指导我在这方面缺少什么?我是 quicblox 的新手。
【问题讨论】:
标签: android firebase push-notification quickblox