这是我的清单
<service android:name=".fcm.PshycoFirebaseMessagingServices">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".fcm.PshycoFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
当应用程序处于后台并且通知到达时,默认通知将会运行并且不会运行我的代码onMessageReceived.
这是我的onMessageReceived代码.如果我的应用程序在前台运行,而不是在后台应用程序时,则调用此方法.如何在应用程序处于后台时运行此代码?
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试Firebase云消息传递API,因为控制台无法使用所有功能(特别是在应用程序处于后台时自定义通知).但由于某些原因,我无法让它工作,它总是出现401错误.我调查了这个的原因,并在重新生成新的服务器密钥后尝试了它,但错误保持不变.令人惊讶的是,当我生成新的服务器密钥时,它不会反映在Firebase控制台中,并且它将服务器密钥显示为空.此外,我尝试将我的IP地址添加到服务器白名单IP但仍然没有运气.我附上了一个我用Postman做的请求的截图(我用服务器密钥代替serverKey.
我正在尝试在用户点击通知时尝试打开特定活动,当应用在后台时,使用一些额外参数.我正在使用它click_action并且它工作正常,该应用程序打开所需的活动.
现在我需要服务器将一个额外的参数a传递id给此Activity,以便我可以提供与通知相关的所需详细信息.就像电子邮件应用程序一样,当我们点击通知时,会打开该特定电子邮件的详细信息.
我怎样才能做到这一点?
android android-notifications firebase-cloud-messaging firebase-notifications
当我的应用程序打开并收到通知时,我希望能够立即打开相关活动,而无需用户点击通知.
这个问题非常相似:收到firebase通知的打开应用程序(FCM)
但它在应用程序处于后台时打开应用程序,我需要在应用程序处于前台时执行此操作.
当您的应用在后台时发送通知.在这种情况下,通知将传递到设备的系统托盘.用户点按通知会默认打开应用启动器.具有通知和数据有效负载的消息,包括后台和前台.在这种情况下,通知将传递到设备的系统托盘,并且数据有效负载将在启动器活动的附加内容中传递.
这是我的命令 onMessageReceived
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
sendNotification( remoteMessage);
}
}
/**
* Create and show a simple notification containing the received FCM message.
*
* @param remoteMessage FCM message …Run Code Online (Sandbox Code Playgroud) android firebase firebase-cloud-messaging firebase-notifications
我在Android应用中使用Firebase作为我们的消息服务.我已经对Firebase进行了相当多的研究,我理解无论应用程序是在前台运行还是现在运行都会改变onMessageReceived方法中收到的数据类型.
我想要完成的是解析来自Remotemessage的传入数据,并根据自定义标记执行与它不同的操作.IE,如果数据映射包含一个名为"My_Custom_Tag"的字段,我想完全覆盖弹出的标准firebase消息并编写一个自定义消息.
问题是,当应用程序在后台运行时,我放入onMessageReceived的任何代码都不会被触发.当应用程序在前台运行时,它可以正常工作,但如果应用程序在后台,则无法检测/接收任何内容.
以下是一些示例代码:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map<String, String> aMap = remoteMessage.getData();
//Custom object here for easier parsing
PushNotificationsPojo pojo = this.convertResponseToPojo(aMap);
if(pojo == null){
passToFirebase(remoteMessage);
return;
}
if(pojo.getData().getCustomTag().equals(PushNotificationsPojo.ID_TAG_CHAT_MESSAGE)) {
createCustomNotification1(pojo);
} else if (pojo.getData().getCustomTag().equals(PushNotificationsPojo.ID_TAG_SOME_OTHER_MESSAGE)){
createCustomNotification2(pojo);
} else if (pojo.getData().getCustomTag().equals(PushNotificationsPojo.ID_TAG_STUFF_AND_WHATNOT)) {
createCustomNotification3(pojo);
} else {
passToFirebase(remoteMessage);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何编辑MyFirebaseMessagingService以便我可以检查传入的数据,确定标记信息,并决定将其传递给firebase,以便它可以使用标准处理或不将其传递给firebase并编写我的我的应用程序在后台运行时,我自己的自定义显示通知?
谢谢大家!
我正在尝试通过新的Firebase推送通知服务向我的用户发送一些数据.
我正在使用"消息文本" - "dbupdate"添加一些"键值"自定义数据项,以检测它是更新消息还是我要向用户显示的正常推送通知.
在我的接收器中,我检查我是否有自定义数据并运行更新,如果为真.如果不是这种情况,我会通过短信显示正常通知.
它仅在我的应用程序打开时有效.如果应用程序关闭,则无论如何都会显示通知,而我的if检查甚至没有运行,
一些代码:
public class PushMessageService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map<String,String> data = remoteMessage.getData();
String link = data.get("link");
String name = data.get("name");
if (link!=null) {
Log.d("link",link);
Log.d("name",name);
UpdateHelper.Go(this, link, name);
}
else {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_shop_white_24dp)
.setAutoCancel(true)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody());
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(5, mBuilder.build());
}
}
}
Run Code Online (Sandbox Code Playgroud)
这里举例说明
为什么会这样?即使应用程序关闭,我该怎么做才能运行我的代码?
我读
但这些不是react-native-firebase的解决方案。
我正在react-native-firebase用来处理通知。在前台,一切正常。我坚持使用后台状态。
我正在做一个聊天项目并制作一对一通话功能。当客户有电话时,我会向他们推送数据通知。在 iOS 中,我在客户端收到通知时使用了 CallKit,它运行良好。但是在 Android 中我有一个问题:我可以显示 ConnectionService UI 进行调用,但无法连接到我的 Web 套接字服务器,因为它在 Headless JS 服务上运行。所以我尝试自动打开应用程序。我想将呼叫屏幕显示为 Skype,并接受/拒绝呼叫。(Skype 可以在我有电话时启动该应用程序)
总结,成功步骤:
卡在这里:
TL;DR - 如何从 Headless JS 服务启动/运行/打开 Android 应用程序?
我深入研究 react-native-firebase,它捕获通知onMessageReceived并将通知消息发送到 Headless JS 服务。
// If the app is in the background we send it to the Headless JS Service
Intent headlessIntent = new Intent(
this.getApplicationContext(),
RNFirebaseBackgroundMessagingService.class …
当用户点击从 Firebase 控制台发送的通知时,我需要启动一个特定的 Android Activity,只有当用户点击通知时。如何在以下 2 种情况下完成此操作:
android-activity firebase firebase-cloud-messaging firebase-notifications
有人有经验吗?我正在调查迁移,但由于我们已经在GCM上发布了应用程序,每天有成千上万的用户和数千个通知,我不愿意因为害怕破坏现有服务.有人管理平稳过渡吗?
具体来说,在教程(https://developers.google.com/cloud-messaging/android/android-migrate-fcm)中,第一步是"导入Google项目".这是单向操作吗?现有的GCM服务器解决方案和部署的GCM应用程序是否会继续运行?
或者,最好的办法是创建一个新项目,并维护两个服务器解决方案,直到GCM部署的应用程序逐步淘汰?