Tag: firebase cloud messaging

FCM:没有调用onMessageReceived,即使将msg发送到fcm后也没有通知?

我正在开发一个应用程序,我想通过PHP实现FCM推送通知。 所以我制作了两个java文件:1.FirebaseInstanceID(工作正常并在数据库中正确获取令牌)2.FirebaseMessagingSerivice(未调用) 我的FirebaseMessagingService.java package com.example.xyz; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.support.v4.app.NotificationCompat; import com.google.firebase.messaging.RemoteMessage; public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService{ @Override public void onMessageReceived(RemoteMessage remoteMessage) { showNotification(remoteMessage.getData().get(“message”)); } private void showNotification(String message) { Intent i = new Intent(this,Dashboard.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setAutoCancel(true) .setContentTitle(“FCM Test”) .setContentText(message) .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark) .setContentIntent(pendingIntent); NotificationManager […]

Java Server – 使用POST发送Push到Google Firebase Cloud

在我测试推送通知正在与Postman合作时,我想在我的应用程序中发送消息时向FCM发送推送请求。 调用的函数将转到我的Java服务器并调用如下函数: @POST @Consumes(MediaType.APPLICATION_JSON) public Response sendMsg(Message m) throws ExceptionFacade { … } 因此,每次调用此函数时,我都希望使用json向https://fcm.googleapis.com/fcm/send发送POST请求。 我想知道是否已经为java服务器准备好了代码? 还有一些帮助如何实现它。 另外我不明白我是否可以使用php文件来执行此操作(我发现这样的内容https://github.com/Paragraph1/php-fcm )。 我正在使用angularjs。 感谢你们 !

应用在后台时的Android通知

我正在从谷歌firebase发送针对Android 5.0的Android应用程序的推送通知: 我的推送通知代码是: @Override public void onMessageReceived(RemoteMessage remoteMessage) { String badge = “0”; Uri uri = Uri.parse( getString(R.string.app_host_name) ); Map data = remoteMessage.getData(); if (data.size() > 0) { try { uri = Uri.parse( data.get(“link”) ); badge = data.get(“badge”); } catch (NullPointerException e) { // } } if (remoteMessage.getNotification() != null) { RemoteMessage.Notification notification = remoteMessage.getNotification(); […]

即使应用程序未运行,也要处理onMessageReceived()和onTokenRefresh()

我有一个有2项服务的应用程序: MessagingService extends FirebaseMessagingService 和 InstanceIDService extends FirebaseInstanceIdService 在AndroidManifest.xml文件中声明了。 问题是,当我的应用程序的进程被强制关闭时,服务也会被杀死。 我希望他们不被杀死。 我听说过Service类的START_STICKY标志,但是我不能覆盖这些服务中的onStartCommand()方法,以便返回这个标志……

如何在Android中保存FCM令牌?

我跟着这个在Firebase注册我的deivce 在这里,我试图显示并保存通知令牌 public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { private static final String TAG = “MyFirebaseIIDService”; @Override public void onTokenRefresh() { String refreshedToken = FirebaseInstanceId.getInstance().getToken(); Log.d(TAG, “Refreshed token: ” + refreshedToken); storeToken(refreshedToken); } private void storeToken(String token) { //saving the token on shared preferences SharedPrefManager.getInstance(getApplicationContext()).saveDeviceToken(token); } } 当我尝试注册时,总是说Token Token not generated从MainActivity Token not generated 所以我的应用程序已连接到Firebase ..我知道FirebaseInstanceIdService已弃用我也试过这个 […]

来自Java而不是Firebase控制台的Firebase Cloud Messaging通知

我是Firebase的新用户,当我的Java应用程序尝试使用客户端的Firebase令牌发送通知/消息时,我遇到错误,例如错误的发件人ID和HTTP状态401的身份validation错误。 请注意,使用Firebase控制台,我可以将消息发送到客户端。 对于客户端应用程序,我执行了以下操作: 从这里克隆Firebase messaging快速入门应用程序 – https://github.com/firebase/quickstart-android/tree/master/messaging – 已经设置了Firebase依赖等。 在Android Studio加载了克隆的应用程序。 使用Firebase控制台,创建了一个名为“ My Notification Client的新项目,并使用com.google.firebase.quickstart.fcm添加了一个应用,作为Android应用的包名称。 下载了添加到新创建项目的Android应用的google-services.json文件,并将其复制到messaging/app/文件夹,并与Android Studio成绩文件同步。 创建了一个模拟器并在Android Studio运行应用程序。 当应用程序加载到模拟器中时,单击“ Log Token按钮以在Android Studio的Android Monitor选项卡中捕获客户端的Firebase标记。 使用Firebase控制台,选择新创建的项目“ My Notification Client ,单击左窗格中的“ Notifications链接,并通过粘贴上一步中捕获的Firebase令牌向设备发送通知。 这很棒! 下一步是使用单独的简单Java应用程序(最终将成为通知服务器)将通知发送到客户端,而不是使用Firebase控制台。 为此,我按照此处列出的步骤进行了操作 – https://firebase.google.com/docs/server/setup#prerequisites 。 具体来说,这些是我执行的步骤: 在Firebase Console中创建了一个名为My Notification Server的新项目。 使用Firebase控制台中的Settings > Permissions ,创建新服务帐户并下载serviceAccountCredentials.json文件。 在Eclipse中创建了一个新的maven项目,并在pom.xml中添加了以下依赖项: com.google.gcm gcm-server 1.0.0 com.googlecode.json-simple json-simple 1.1.1 com.google.firebase firebase-server-sdk 3.0.0 […]

如果app在后台,如何使用fcm从服务器发送数据?

我从服务器向我的应用程序发送fcm通知。 我从服务器发送包含user_id的数据。 如果app在前台,我将在FirebaseMessageService类中获取此userId。 但是当应用程序处于后台时却没有得到它。 由于FirebaseMessagingService类仅在应用程序位于前台时才会执行。 那么当应用程序处于后台时,如何获得此ID? public class MyFirebaseMessagingService extends FirebaseMessagingService { private static final String TAG = “MyFirebaseMsgService”; private String mUserId; private Boolean mUpdateNotification; @Override public void onMessageReceived(RemoteMessage remoteMessage) { //Displaying data in log //It is optional Log.d(TAG, “From: ” + remoteMessage.getFrom()); Log.d(TAG, “Notification Message Body: ” + remoteMessage.getNotification().getBody()); String clickAction = remoteMessage.getNotification().getClickAction(); mUserId […]

使用GWT时找不到Firebase服务工作者(404错误)

我想在我的GWT web应用程序中使用firebase云消息传递服务,但我遇到了一些问题。 应用程序应该能够注册firebase服务工作者并使用它的特定令牌连接到服务。 此令牌,收到的消息和令牌更改时的事件应该可以在我的GWT Java代码中访问。 当我尝试使用handle.getToken()创建令牌时发生错误。 我收到此错误消息: 获取脚本时收到错误的HTTP响应代码(404)。 无法加载资源:net :: ERR_INVALID_RESPONSE browserErrorMessage:“无法注册ServiceWorker:获取脚本时收到了错误的HTTP响应代码(404)。” 代码:“messaging / failed-serviceworker-registration”消息:“消息:我们无法注册默认服务工作者。无法注册ServiceWorker:获取脚本时收到错误的HTTP响应代码(404)。(消息/失败-serviceworker注册)“。 stack:“FirebaseError:Messaging:我们无法注册默认服务工作者。无法注册ServiceWorker:获取脚本时收到错误的HTTP响应代码(404)。(messaging / failed-serviceworker-registration).↵at https://www.gstatic.com/firebasejs/3.5.2/firebase-messaging.js:41:225″__proto__:错误 它尝试访问以注册服务工作者的URL是: http : //127.0.0.1 : 11111 / firebase-messaging-sw.js 所以很明显问题是它试图从我的本地主机地址而不是其他firebase JS文件所在的位置访问javascript。 所以我的问题是如何更改它,以便从正确的源加载文件? 这些脚本包含在我的HTML文件中: // Initialize Firebase var config = { apiKey: “AIzaSyBxdZNXHiLR1IC8Wrw3Y6q_5DFoN8hn_UY”, authDomain: “fir-test-848de.firebaseapp.com”, databaseURL: “https://fir-test-848de.firebaseio.com”, storageBucket: “fir-test-848de.appspot.com”, messagingSenderId: “974661154941” }; firebase.initializeApp(config); 这是我的Java代码: 公共类FireBase { private JavaScriptObject […]

Firebase云消息传递API弹簧

我必须在Spring Java中创建一个Rest API用于多层arch,其中需要为Firebase云消息传递(FCM)构建DAO,Controller,Service Manager以向Android应用程序发送推送通知消息,但我无法配置Java中的服务器,用于向设备发送通知。 我怎么能?