我正在我的应用程序中实现FCM(Firebase消息服务).这里似乎都没问题,除非app处于后台状态我无法提取预期的通知数据.
基于概念:FCM中有两种类型的消息:
display-messages:这些消息仅在您的应用处于前台时才有效.
数据消息:即使您的应用处于后台,这些消息也能正常工作当我们的应用处于后台时,Android会将通知消息定向到系统托盘.
处理数据消息时,您的通知应具有click_action ="YOUR_ACTION"字段.
我的信息会是这样的:
{
"data": {
"body": "here is body",
"title": "Title",
"click_action": "YOUR_ACTION"
},
"to": "ffEseX6vwcM:APA91bF8m7wOF MY FCM ID 07j1aPUb"
}
Run Code Online (Sandbox Code Playgroud)
活动将显示清单文件将如下所示的消息:
<activity
android:name=".NotificationActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Dialog"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="YOUR_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
点击通知后,它将重定向到我的NotificationActivity.在我的NotificationActivityin onCreate和onNewIntent方法中,我使用这种方式提取消息:
Bundle bundle=getIntent().getExtras();
if(bundle!=null) {
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
Log.d("DATA_SENT", String.format("%s %s (%s)", key,
value.toString(), value.getClass().getName()));
}
} …Run Code Online (Sandbox Code Playgroud) 我正在向Android和iOS设备发送推送通知......我正在使用数据消息,因为我需要自定义键值对,我需要在应用程序在后台时使用它们
我的有效载荷是这样的:
{
"to": "device token here",
"content_available":true,
"priority":"high",
"data": {
"key1": "value1",
"key2": "value2",
"key3": "value3",
}
}
Run Code Online (Sandbox Code Playgroud)
这在Android上工作正常,并且通知来自iOS,通知不会通过...只有在我在有效负载中包含通知时才会通过这样:
{
"to": "device token here",
"notification": {
"title": "test",
"text": "MY Test"
},
"content_available":true,
"priority":"high",
"data": {
"key1": "value1",
"key2": "value2",
"key3": "value3",
}
}
Run Code Online (Sandbox Code Playgroud)
第二种方法的问题是通知不再是数据消息,所以当应用程序在android的后台时我无法使用它...如何解决这个问题 - 我需要通知才能在两个平台上工作,发送数据对,理想情况下即使应用程序在后台
push-notification apple-push-notifications android-notifications firebase
FCM服务:
public class FCMService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.i(Constants.TAG,"onMessageReceived");
Log.i(Constants.TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(Constants.TAG, "Message data payload: " + remoteMessage.getData());
}
if (remoteMessage.getNotification() != null) {
Log.d(Constants.TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
}
}
Run Code Online (Sandbox Code Playgroud)
App Gradle:
compile 'com.google.firebase:firebase-messaging:10.2.6'
Run Code Online (Sandbox Code Playgroud)
表现:
<service android:name="communications.FCMService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
- 我从FCM控制台发送消息但没有到达.发送消息时,FCM控制台显示确定.
-I从java服务器发送消息,消息不到.发送消息时,Java服务器显示OK.
- 发送消息我在Android设备中使用生成的令牌.
- 之前,我错误地导入FCM库,错误已解决.每次发送邮件时发生过去的错误,Android上都会发生异常.现在什么也没收到.
- 我在Android设备上有一个Internet连接,我通过GCM(而不是FCM)从我过去实现的另一个应用程序接收消息.
-App在前台.
有些日志使用"fcm"过滤器.我发送消息时会收到此日志.
08-14 12:09:25.640 800-4739/? D/PowerManagerService: acquireWakeLockInternal: lock=862109980, flags=0x1, …Run Code Online (Sandbox Code Playgroud) 我使用https://github.com/zo0r/react-native-push-notification得到推送通知和onNotification工作时,应用程序是aspected Active或在Background我收到的通知,但是当我杀死的应用程序,我只得到了通知和onNotification没有解雇任何一个可以请帮助我搜索一个解决方案但没有任何效果,当onNotification被解雇时,我增加了Android徽章计数是否有另一种方法来增加Android徽章时应用程序被杀?
"react-native": "0.55.3",
"react-native-push-notification": "3.0.2"
Run Code Online (Sandbox Code Playgroud)
我的代码
const options = {
// (optional) Called when Token is generated (iOS and Android)
onRegister: (token) => {
this._TOKEN = token.token;
this._addToPushChannels(channel);
},
onNotification: (notification) => {
console.log(notification);
if (notification['foreground']) {
}
//Notification from the background or when the app is killed
if (!notification['foreground']) {
if (Platform.OS !== 'ios' && Platform.Version < 26) {
this._messageCount++;
// console.log('this._messageCount ', this._messageCount);
let BadgeAndroid = require('react-native-android-badge');
BadgeAndroid.setBadge(this._messageCount);
}
}
// required …Run Code Online (Sandbox Code Playgroud) 我最近更新了我的应用程序,通过FCM发送消息,当应用程序在Jelly Bean上运行时,它运行良好.问题是,它不是棒棒糖和应用程序在后台.
我阅读了文档,并指出当有效载荷是数据消息时,它将由onMessageReceived()处理.我发送数据有效负载,而不是通知,只要它是JellyBean就可以正确处理.对于Lollipop,它仅在应用程序位于前台时处理消息.如果没有,没有任何反应.
这就是我的FirebaseMessagingService的开头如下所示:
public class FirebaseBroadcastReceiverService extends FirebaseMessagingService {
private final String TAG = FirebaseBroadcastReceiverService.class.getName();
@Override
public void onMessageReceived(RemoteMessage message){
Log.i(TAG, "A message is received");
String from = message.getFrom();
Map<String, String> data = message.getData();
.....
}
}
Run Code Online (Sandbox Code Playgroud)
清单:
<application
android:name=".controller.application.AppResources"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher_shadow"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.Black.NoTitleBar">
<service
android:name=".model.firebase.FirebaseListenerService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name=".model.firebase.FirebaseBroadcastReceiverService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
.......
</application>
Run Code Online (Sandbox Code Playgroud)
有效载荷:
{
"data": {
"test": …Run Code Online (Sandbox Code Playgroud) 我想在后台和前台处理firebase通知消息.我将发送一条消息,其中包含来自开发人员的youtube链接,当用户点击通知栏时,它必须指示用户打开链接.有谁知道它是如何完成的?
public void onMessageReceived(RemoteMessage remoteMessage) {
// [START_EXCLUDE]
// There are two types of messages data messages and notification messages. Data messages are handled
// here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
// traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
// is in the foreground. When the app is in the background an automatically generated notification is displayed.
// When the user …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 控制台接收文本、图像以及两者作为推送通知。我也想从 Firebase 控制台向应用用户发送一个 URL 作为通知。单击通知时。用户将被重定向到特定的 URL,例如。www.google.com如何在以下代码中执行此操作?
package com.example.khan.andronotification;
/**
* Created by AndroidBash on 20-Aug-16.
*/
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FirebaseMessageService";
Bitmap bitmap;
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message …Run Code Online (Sandbox Code Playgroud) 使用FCM的Android推送通知在后台应用程序时无法处理.通知栏中显示默认消息.
任何人都可以帮助我在后台应用程序时如何处理消息.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Run Code Online (Sandbox Code Playgroud)
}
当应用程序在后台时,不会调用此方法.任何帮助对我都有很大的帮助.
我正在尝试在我的应用中实施FCM通知.我已阅读FCM数据消息类型即使在应用程序处于后台时也会收到通知,所以我试图在onMessageRecieved方法中实现这样的意外响应,如下所示:
{title =2, message={"Status":"UNASSIGNED","CompanyName":"gd","LastModifiedDateTime":"2017-04-25 18:59:41","IsPartRequired":false,"ProblemCategory":"CONFIGURATION","IsGeneralClaim":false,"RegistrationID":1057,"IncidentCode":"INS\/2017\/04\/25-0010","StatusID":0,"CreatedDateTime":"2017-04-25 18:59:41","IsInstallationCall":false}}
Run Code Online (Sandbox Code Playgroud)
不知道如何解析这个从标题和消息中获取单独的值让我发布我的firebase消息代码:
public class FireBaseMessage extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map<String,String> data = remoteMessage.getData();
Log.d(TAG, "From: " + data.toString());
//
}
}
Run Code Online (Sandbox Code Playgroud)
在这条日志消息中我得到的反应是如何从中获取价值的尝试如下:
int title=data.get("title");
Run Code Online (Sandbox Code Playgroud)
获取空指针,因为它不是有效格式.在我的服务器端,我试图发布像这样的json格式:
{
"to":"es_OToDkj00:APA91bFqxbVMAaXy5fPtDbNVAkIwyVrPCmfGci2otHZPvdRoXPv-oDdjgtLR92Nqe8w6f57nCVceLbc3_zBWsInG9g1Pfdp3LvsMKyuaiYps0L1y3tn0N0XbzGseEI6jyiqs1r-sT9lb",
"data":{
"message":{
"RegistrationID":1057,
"IncidentCode":"INS/2017/04/25-0010",
"CompanyName":"ABM INFOTECH",
"StatusID":5,
"Status":"ASSIGNED",
"CreatedDateTime":"2017-04-25T12:03:45",
"LastModifiedDateTime":"2017-04-25T18:59:41",
"ProblemCategory":"CONFIGURATION",
"IsPartRequired":false,
"IsInstallationCall":false,
"IsGeneralClaim":false
},
"title ":"1"
}
Run Code Online (Sandbox Code Playgroud)
不知道我在哪里弄错了.谁能帮我?提前致谢!