我正在使用Firebase,并在应用程序处于后台时测试从我的服务器向我的应用发送通知.通知成功发送,甚至出现在设备的通知中心,但是当通知出现或甚至我点击它时,我的FCMessagingService内的onMessageReceived方法永远不会被调用.
当我在我的应用程序位于前台时对此进行测试时,调用了onMessageReceived方法,一切正常.当应用程序在后台运行时会出现此问题.
这是预期的行为,还是有办法解决这个问题?
这是我的FBMessagingService:
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class FBMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.i("PVL", "MESSAGE RECEIVED!!");
if (remoteMessage.getNotification().getBody() != null) {
Log.i("PVL", "RECEIVED MESSAGE: " + remoteMessage.getNotification().getBody());
} else {
Log.i("PVL", "RECEIVED MESSAGE: " + remoteMessage.getData().get("message"));
}
}
}
Run Code Online (Sandbox Code Playgroud) 这是我第一次使用FCM.
我从firebase/quickstart-android下载了一个示例,我安装了FCM Quickstart.But我甚至无法从日志中获取任何令牌,甚至点击应用程序中的LOG TOKEN按钮.
然后我尝试使用Firebase控制台发送消息并设置为我的应用程序包名称.我收到任何传入消息.
我想知道可以使用FCM吗?GCM一切正常.
解:
因为我不是Android开发人员,只是一个后端开发人员.所以我需要一些时间来解决它.在我看来,示例应用程序中存在一些错误.
码:
RegistrationIntentService.java
public class RegistrationIntentService extends IntentService {
private static final String TAG = "RegIntentService";
public RegistrationIntentService() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
String token = FirebaseInstanceId.getInstance().getToken();
Log.i(TAG, "FCM Registration Token: " + token);
}
}
Run Code Online (Sandbox Code Playgroud)
MyFirebaseInstanceIDService.java
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
/**
* Called if InstanceID token is updated. This may occur if the security of …Run Code Online (Sandbox Code Playgroud) 搜索文档后,我找不到任何有关如何使用FCM将设备发送到设备消息的信息,而无需使用外部服务器.
例如,如果我正在创建一个聊天应用程序,我需要向用户发送有关未读消息的推送通知,因为它们不会一直在线,我不能在后台始终连接到持久服务实时数据库,因为这太资源了.
那么当某个用户"B"向他/她发送聊天消息时,如何向用户"A"发送推送通知?我是否需要外部服务器,还是仅使用Firebase服务器?
我正在使用离子框架(Web技术)开发android/ios应用程序,我想在新的firebase功能FCM的帮助下添加推送通知.
现在我正在看以下文档:
https://firebase.google.com/docs/cloud-messaging/chrome/client#project-setup
说的是:
- Chrome中的网站可以通过服务工作者和网络实现推送消息传递
- 应用程序符合Webpush标准.Chrome应用和扩展程序可以直接通过chrome.gcm
API 访问FCM服务.
这是否意味着我可以在我的离子应用程序中使用它同时用于android/ios,因为app是使用cordova构建的?
如果有任何实现的例子,我可以看到和学习,这将是非常有帮助的.
谢谢
push-notification cordova firebase ionic-framework firebase-cloud-messaging
有没有办法通过FCM从一台Android设备向与Firebase数据库连接的其他设备发送上游通知消息.
我知道XMPP服务器然后可以接收上游消息并将通知发送到其他设备.要接收与上游API一起发送的消息,我需要实现XMPP服务器,但还有其他方法吗?
我可以从Firebase控制台向单个设备,主题和用户细分发送通知.
我想将推送通知发送到用户段.我搜索了很多,但我只是通过脚本向单个用户或主题发送通知而不是用户段.
我尝试了下面的代码
var client = new RestClient("https://fcm.googleapis.com/fcm/send");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "key=mykey");
request.AddParameter("application/json", "\n\n{\"to\" : \"user-segment-name\",\n\"notification\" : {\n \"body\" : \"test message\",\n \"title\" : \"Portugal vs. Denmark\"\n },\n \"priority\":\"high\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Response.Write(response.Content);
Run Code Online (Sandbox Code Playgroud)
我收到的答复如下
{"multicast_id":5837227475989925972,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
Run Code Online (Sandbox Code Playgroud) 我想将推送通知中的图像和图标从Serverside(php)发送到应用程序。

我在Google上进行了搜索,但无法获得正确的结果。我得到了FCM PHP代码。我使用这些代码发送通知,但是当我使用“图像和图标”参数图像时,通知中不会收到。
在GCM中,很容易在“推送”通知中发送图标和图像
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array(
"title" => "SamplePush Application",
"style" => "inbox"; //picture/inbox,
"message" => "I am just testing Push notification",
"notId" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"summaryText" => "Venha provar os nossos Gins",
"image" => "http://gintonico.com/content/uploads/2015/03/fontenova.jpg",
"picture" => "http://media5.letsbonus.com/products/285000/285006/14014409744462-0-1700x690.jpg"
) ,
Run Code Online (Sandbox Code Playgroud)
如果有人可以使用FCM发送通知中的图像和图标,请帮助我。
如果没有Managed by google像blogger模板那样的托管/自己的服务器,我正在寻找设置FCM服务器协议的方法,并设置项目的依赖项.
我在这个问题中看到了.一些答案包含类似于使用"okhttp3"的改装代码的代码
String SCOPE = "https://www.googleapis.com/auth/firebase.messaging";
String FCM_ENDPOINT
= "https://fcm.googleapis.com/v1/projects/zoftino-stores/messages:send";
GoogleCredential googleCredential = GoogleCredential
.fromStream(new FileInputStream("firebase-private-key.json"))
.createScoped(Arrays.asList(SCOPE));
googleCredential.refreshToken();
String token = googleCredential.getAccessToken();
final MediaType mediaType = MediaType.parse("application/json");
OkHttpClient httpClient = new OkHttpClient();
Request request = new Request.Builder()
.url(FCM_ENDPOINT)
.addHeader("Content-Type", "application/json; UTF-8")
.addHeader("Authorization", "Bearer " + token)
.post(RequestBody.create(mediaType, jsonMessage))
.build();
Response response = httpClient.newCall(request).execute();
if (response.isSuccessful()) {
log.info("Message sent to FCM server");
}
Run Code Online (Sandbox Code Playgroud)
目前我在我的Android应用程序中使用blogger api通过使用改造和REST API作为json对象来集成博客内容.这是我用来检索博客的BloggerAPI类
public class BloggerAPI {
public static final String BASE_URL …Run Code Online (Sandbox Code Playgroud) 我必须在 Spring Java 中为多层架构创建一个 Rest API,其中需要为 Firebase 云消息传递 (FCM) 构建 DAO、控制器、服务管理器以将推送通知消息发送到 android 应用程序,但我无法配置Java 中的服务器,用于向设备发送通知。我怎么能?
java spring-mvc firebase spring-boot firebase-cloud-messaging
您知道我可以在哪里查看和管理 FCM 中的主题(排序或管理控制台)吗?
谢谢!
* 更新 * 使用 FCM 科尔多瓦插件 (FCMPlugin),我在我的应用程序中编写了以下内容:
FCMPlugin.getToken(function(token){
console.log('FCMPLUGIN: ', token);
alert(token); // the token pops up in my app
});
FCMPlugin.subscribeToTopic('topics/chats/' + currentUser.auth.uid);
Run Code Online (Sandbox Code Playgroud)
没有错误,一切似乎都正常,但是当我转到通知控制台时,我看不到我的主题:

我在一些文档中读到,向不存在的主题发送消息会创建它,所以我尝试通过 FCMPlugin ( https://cordova-plugin-fcm.appspot.com/ )的测试控制台,但我的主题中仍然没有主题控制台......知道我做错了什么吗?
我正在创建一个聊天应用程序,如果此人有新消息,我想使用 fcm 发送通知,但我不知道如何继续。我发现的所有教程都用于从 firebase 发送消息。但是我想在有新消息给这个人时自动发送
我想要一个代码来将通知从一台设备发送到多台设备上的特定主题,并且我想在订阅该主题的设备上显示该通知?我将使用 firestore 来存储数据和存储令牌,并使用 Firebase 消息传递来发送通知
新的Firebase通知服务允许我们使用控制台用户界面向所有移动应用用户发布通知.
但我找不到Firebase Notifications Service的任何REST API.我想根据事件通过服务器端代码自动向移动用户发送通知.Firebase Notifications Service是否具有可通过HTTP/S访问的API?
android ios firebase firebase-cloud-messaging firebase-notifications
firebase ×11
android ×7
flutter ×2
ios ×2
cordova ×1
dart ×1
iphone ×1
java ×1
javascript ×1
json ×1
php ×1
retrofit ×1
spring-boot ×1
spring-mvc ×1
xmpp ×1