发送两个通知时,第二个通知将覆盖通知中心中的第一个通知.根据文档,这应该只在使用标签时发生:
"tag":指示每条通知消息是否在通知中心上生成新条目.如果未设置,则每个请求都会创建一个新通知.如果已设置,并且已显示具有相同标记的通知,则新通知将替换现有通知.
然而,无论我是否为标签设置了值,这种情况一直发生在我身上.
我甚至尝试设置一个随机标签&collapse_key(据我所知,在这种情况下我不应该相关,但我试了一下).仍然没有帮助.这是我发送的通知对象的示例:
{
"tokens":[
"my-device-token"
],
"profile":"my-profile-tag",
"notification":{
"message":"message",
"android":{
"payload":{
"collapse_key":9918519,
"tag":2825928
}
}
}
}
Run Code Online (Sandbox Code Playgroud) android push-notification google-cloud-messaging ionic-framework firebase-cloud-messaging
我正在使用Firebase创建我的第一个应用程序.
我一步一步地在我的应用程序中添加firebase.
完成所有步骤后,我遇到了以下错误.
我的build.gradle文件:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.firebase:firebase-core:9.0.2'
compile 'com.google.firebase:firebase-messaging:9.0.2'
}
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)
我还在Project level build.gradle中添加了以下行.
classpath 'com.google.gms:google-services:3.0.0'
Run Code Online (Sandbox Code Playgroud)
有什么问题,我找不到.有帮助吗?
我尝试使用 PHP 代码/网络浏览器发送 FCM。
但问题是当我使用 PHP 网络浏览器发送它时:
而且我只能使用 Firebase 控制台将 FCM 通知发送到真实的手机设备。
有人可以帮忙吗?代码如下。
<?php
require "init.php";
global $con;
if(isset($_POST['Submit'])){
$message = $_POST['message'];
$title = $_POST['title'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "AAAA2gV_U_I:APA91bHA28EUGmA3BrDXFInGy-snx8wW6eZ_RUE7EtOyM99pbfrVZU_ME-FU0O9_dUxYpM30OYF8KWYlixod_PfwbgLNoovzdkdJ4F-30vY8X_tBz0CMrajCIAgbNVRfw203YdRGli";
$sql = "SELECT fcm_token FROM fcm_table";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_row($result);
$key = $row[0];
$headers = array('Authorization:key=' .$server_key, 'Content-Type:application/json');
$fields = array('to' => $key, 'notification' => array('title' => $title, 'body'=> $message));
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true); …Run Code Online (Sandbox Code Playgroud) 我正在尝试fragment通过 Firebase 云消息传递在 Activity 中打开一个初始化。
片段调用在应用程序打开时起作用,但是一旦我关闭应用程序,推送通知只会打开 Activity 而不是片段。
我的活动.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//All my initial code
Intent i = getIntent();
Bundle extras = i.getExtras();
if(extras != null) {
String push = extras.getString("push");
if (push != null) {
Integer id = Integer.parseInt(extras.getString("id"));
goToDetalleDenuncia(id);
}
}else
goToMenu();
}
Run Code Online (Sandbox Code Playgroud)
我可以做些什么来调试(或解决)这个问题?我无法使用 Logcat(至少使用 eclipse),因为此时应用程序已关闭
我使用Firebase作为后端数据库创建了一个类似于Instagram的应用程序。该应用程序具有所有功能,即用户可以喜欢您的帖子,对您的帖子发表评论等。但是,现在我受困于通知部分。我已经阅读了一些有关FCM的文档,并遵循了一些教程。但是,我找不到任何关于如何创建通知的特定教程,该通知的标题是喜欢/发表评论的人的名字,标题是评论的内容。我是否必须使用PHP和mySQL来完成所有这些工作?还是可以仅使用JAVA来完成?
我一直试图在我的应用程序中获取firebase推送通知.我已尝试过互联网上的所有内容但无法找到解决方案.我一直在后台收到通知,但是当App在前台时,我无法收到通知.但是当我在"didReceiveRemoteNotification"中打印userInfo时,我在控制台中收到消息.任何帮助都将不胜感激.
import Firebase
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate{
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//FirebaseApp.configure()
self.initializeFCM(application)
let token = InstanceID.instanceID().token()
debugPrint("GCM TOKEN = \(String(describing: token))")
return true
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error)
{
debugPrint("didFailToRegisterForRemoteNotificationsWithError: \(error)")
}
func application(received remoteMessage: MessagingRemoteMessage)
{
debugPrint("remoteMessage:\(remoteMessage.appData)")
}
func initializeFCM(_ application: UIApplication)
{
print("initializeFCM")
if #available(iOS 10.0, *) // enable new way for notifications on iOS 10
{
let center = UNUserNotificationCenter.current() …Run Code Online (Sandbox Code Playgroud) push-notification ios firebase swift firebase-cloud-messaging
显然,在(OR ||)运算符出现问题之后,当我使用(AND &&)运算符时收到了通知,而当我使用(OR ||)时却没有收到通知。
那么,有没有其他方法可以将通知发送给那些没有(OR ||)运算符的用户(TopicA或TopicB或TopicC)?
我已经尝试了很多解决方案来创建频道,但是当它在Oreo设备中收到时我仍然没有收到通知内容.通知声音即将到来,但通知抽屉中没有实际通知.
以下是我现有的代码.
public class SendNotificationTask extends AsyncTask<Void, Void, Void> {
private static final long DEFAULT_VIBRATION = 300L;
private Context mContext;
private Bundle bundle;
private SharedPreferences sharedPreferences;
private Boolean mIsForeground;
String title;
public SendNotificationTask(Context context, SharedPreferences sharedPreferences, Boolean mIsForeground, Bundle bundle){
this.mContext = context;
this.bundle = bundle;
this.sharedPreferences = sharedPreferences;
this.mIsForeground = mIsForeground;
}
protected Void doInBackground(Void... params) {
try {
String intentClassName = getMainActivityClassName();
if (intentClassName == null) {
return null;
}
if (bundle.getString("body") == null) {
return null;
} …Run Code Online (Sandbox Code Playgroud) android android-notifications firebase-cloud-messaging android-8.0-oreo
我在我的React Native应用程序中将react-native-firebase库用于FCM功能。我遵循了他们网站https://rnfirebase.io/docs/v4.2.x/installation/initial-setup上提供的初始指南。我还为Android设置了Cloud Messaging and Notifications模块。通知正确到达设备。但是,问题是单击通知后,我无法路由到特定屏幕。我正在使用react-navigation库进行导航。我实际上对React本机非常陌生,所以我不知道如何为该功能编写代码。任何帮助表示赞赏。最主要的是我很困惑应该在哪里编写导航代码。另外,即使应用程序关闭并单击通知,我也希望它能正常工作。
hybrid-mobile-app reactjs react-native firebase-cloud-messaging
I get the above error when I try and send messages to devices:
let functions = require("firebase-functions");
const admin = require("firebase-admin");
var serviceAccount = require("./configs.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://pushmessage-bd1eb.firebaseio.com"
});
const db = admin.firestore();
exports.getUsers = functions.https.onRequest(async (req, res) => {
db.collection("users")
.get()
.then(snapshot => {
const messaging = admin.messaging();
let registrationTokens = [];
snapshot.forEach(doc => {
let id = doc.id;
registrationTokens.push(id);
});
console.log(registrationTokens);
// process the tokens
const message = {
data: { title: "Testing", body: "Test" }, …Run Code Online (Sandbox Code Playgroud)