【发布时间】:2017-08-22 11:08:17
【问题描述】:
我会尝试在我的手机托盘上显示个人单身通知,但我无法发财,请帮忙。
我在使用 FireBase 云消息传递时遇到问题,我从设备获取令牌并通过 Google Firebase 通知控制台发送通知测试,但是,通知从未被记录或推送到 android 虚拟设备。 FCM 的文档几乎就是我在下面的代码,而在使用 firebase 时,您还需要做些什么来获得推送通知。我已经完成了文档中指定的所有设置信息(build.gradle 添加、安装 google play 服务等),但仍然没有生成消息。我没有收到到 logcat 或设备的推送通知的代码有什么问题?请让我知道任何有帮助的进一步信息。谢谢。
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) {
FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL);
displayFirebaseRegId();
} else if (intent.getAction().equals(Config.PUSH_NOTIFICATION))
{
String message = intent.getStringExtra("message");
Toast.makeText(getApplicationContext(), "Push notification: " + message, Toast.LENGTH_LONG).show();
txtMessage.setText(message);
}
}
};
displayFirebaseRegId();
}
private void displayFirebaseRegId() {
SharedPreferences pref = getApplicationContext().getSharedPreferences(Config.SHARED_PREF, 0);
String regId = pref.getString("regId", null);
Log.e(TAG, "Firebase reg id: " + regId);
if (!TextUtils.isEmpty(regId))
txtRegId.setText("Firebase Reg Id: " + regId);
else
txtRegId.setText("Firebase Reg Id is not received yet!");
}
@Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
new IntentFilter(Config.REGISTRATION_COMPLETE));
LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
new IntentFilter(Config.PUSH_NOTIFICATION));
NotificationUtils.clearNotifications(getApplicationContext());
}
@Override
protected void onPause() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);
super.onPause();
}
我将添加火基消息库是:
compile 'com.google.firebase:firebase-messaging:11.0.4'
【问题讨论】:
标签: android firebase firebase-cloud-messaging