我有一个扩展 FirebaseMessagingService 的类,其中在 onMessageRecieve() 方法中我使用工作管理器安排工作。在工作类中,我想将 Firebase Id 令牌发布到我的服务器(我正在使用同步齐射请求),但对于 Firebase IdToken,我在工作类中使用 Tasks.await() 但 logcat 显示以下错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.calendarapp, PID: 29746
java.lang.IllegalStateException: Must not be called on the main application thread
at com.google.android.gms.common.internal.Preconditions.checkNotMainThread(com.google.android.gms:play-services-basement@@17.1.1:51)
at com.google.android.gms.common.internal.Preconditions.checkNotMainThread(com.google.android.gms:play-services-basement@@17.1.1:48)
at com.google.android.gms.tasks.Tasks.await(Unknown Source:16)
at com.example.calendarapp.MyWorker$1.onComplete(MyWorker.java:130)
at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Run Code Online (Sandbox Code Playgroud)
Firebase消息服务
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
FirebaseAuth mAuth;
@Override
public void onMessageReceived(@NonNull RemoteMessage …Run Code Online (Sandbox Code Playgroud) multithreading android firebase firebase-cloud-messaging android-workmanager
如何在不使用控制台的情况下向所有用户发送通知?我见过 POSTMAN,但我需要一个令牌才能发送通知,所以我认为这不是一个解决方案。有什么推荐吗?
{
"to":"dj5qoswwRdGUrUVdsrWuDU:APA91bH97tPuf5c27Yxq7ZOk8imVDHAV2CE-jBxxWolGtaKrKW2LIf_0VzDgFSQGwTN852Nst0TYWDl4bEdxRzJ8olowZAEFNC_D-fIWYviRPNROjkrUQyY5-32RKohzZvfFbEcKzb49",
"data":{
"title": "Notificacion PostMan",
"body": "Notificacion PostMan Body"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在 POSTMAN 中所做的一个示例,它适用于特定用户,我需要发送给所有 muy 用户。
java android android-studio postman firebase-cloud-messaging
我正在从 nodejs 服务器使用 firebase 发送推送通知。
消息有效负载是这样的。
const notificationObjNew: any = {
notification: {
body: "demo body",
title: "demo title",
badge : "100",
},
topic: notificationTopic
};
Run Code Online (Sandbox Code Playgroud)
在 IOS 应用程序中,我收到了这个-
{body:demo body,e:1,title:demo title}
Run Code Online (Sandbox Code Playgroud)
这里没有徽章属性。
push-notification node.js ios firebase firebase-cloud-messaging
我在使用 firebase 实现通知时遇到问题。点击事件不起作用。我正在使用 HTTP 1 版本发送不记名令牌。
{
"message": {
"token": "8888****usertoken****8888",
"notification": {
"title": "Background Message Title",
"body": "Background message body"
},
"webpush": {
"fcm_options": {
"link": "https://dummypage.com"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还尝试过 click_action、action 和许多其他变体,但都不起作用。
我使用的是8.0.0版本
根据此链接https://firebase.google.com/docs/cloud-messaging/js/send-multiple上找到的文档,我应该能够使用 fcm_options 来实现它。
我尝试了一种实现 messages.onBackgroundMessage 的解决方法,但是当我实现此方法并使用 self.registration.showNotification 时,通知会显示两次。一个由浏览触发,另一个由此代码触发。
注册 self.addEventListener('notificationclick' 似乎仅在我实现 onBackgroundMessage 时才起作用。
我遵循了文档,但这让我发疯。
这是我的服务人员代码:
importScripts('https://www.gstatic.com/firebasejs/8.0.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.0.0/firebase-messaging.js');
var firebaseConfig = {
apiKey: "xxxxxx",
authDomain: "xxxxxxxx.firebaseapp.com",
databaseURL: "https://xxxxxx.firebaseio.com",
projectId: "xxx-xxx",
storageBucket: "xxx-xxx.appspot.com",
messagingSenderId: "222222222",
appId: "1:2222:web:22222"
};
console.log("fire base messaging")
firebase.initializeApp(firebaseConfig);
const messaging …Run Code Online (Sandbox Code Playgroud) javascript google-chrome push-notification firebase firebase-cloud-messaging
我制作了一个 Flutter 应用程序,刚刚开始使用 Cloud Functions 向其他手机发送推送通知。我通过 API 调用来调用云函数,也就是说,消息被发送,我得到响应代码 200。但有趣的是,大约每隔一段时间(有时更多,有时更少)我得到回复:
状态代码:500,正文:“错误:无法处理请求”
这特别奇怪,因为目前,我每次都发送完全相同的消息!...正如,它是完全相同的 API 调用,没有标头和完全相同的正文。然而,我得到了不同的结果。问题可能是什么?
这是我的云功能:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
exports.sendMsg = functions.https.onRequest((request, response) => {
var decodedBody = JSON.parse(request.body);
const message = decodedBody;
// Send a message to the device corresponding to the provided
// registration token:
admin.initializeApp();
admin.messaging().send(message)
.then((res) => {
// Response is a message ID string.
console.log("Successfully sent message:", res);
response.send("Message sent!\n\n" + res);
})
.catch((error) => {
console.log("Error sending message:", error);
response.send("Error sending …Run Code Online (Sandbox Code Playgroud) javascript http-status-code-500 flutter google-cloud-functions firebase-cloud-messaging
这是我的index.html文件代码
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
Fore more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
-->
<base href="/">
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">
<!-- iOS meta tags & icons --> …Run Code Online (Sandbox Code Playgroud) 我一直在阅读各种教程、其他 SO 线程以及官方 Android 开发人员和 Firebase 文档,但无济于事。我已经尝试了几乎所有的方法,但我已经耗尽了精力和时间,因为我正在修复以前可以工作但不再工作的通知系统。
我正在使用 Azure 通知中心将通知分发到 FCM 以及其他推送通知平台。我的 FCM 项目仅针对 Android。我的应用程序是使用所有依赖项的最新 NuGet 包版本(Xamarin.Forms 5.xxx、Firebase.Messaging 122.0 等)在 Xamarin.Forms 中构建的。
目前,应用程序运行时接收的远程消息或在后台通过继承和实现 FirebaseMessagingService 的自定义服务完美地工作。一旦应用程序被终止(任务切换器 -> 滑动应用程序),在发送更多消息后,我开始看到包含以下内容的 Logcat 消息:
广播意图回调: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg= (有额外内容) }
我知道 Google 改变了 API 26 及更高版本中隐式接收器的工作方式,并且我的理解是此操作 ( com.google.android.c2dm.intent.RECEIVE) 不包含在例外列表中,因此我不知道如何在后台侦听和处理消息。我最近在 2019 年 7 月在其他线程中读到,在应用程序被终止时收到的 FCM 消息应该直接发送到通知托盘。这不会是一个普遍存在的问题,因为许多应用程序在被终止时都会发送通知,因此我希望获得一些当前信息来指导我找到解决方案。
这个意图广播是否由于隐式接收器更改而被取消,或者我做错了什么?
我正在运行 Android 10 的 OnePlus 7 Pro 上进行测试,所以我想知道这是否是其他人在华为和小米等 OEM 设备上提到的电池优化问题。
我的应用程序的目标 Android API 级别 29,最低 API 21
我为我的主要活动和接收器启用了直接启动感知,以确保接收器在启动时和用户打开应用程序之前拦截我的应用程序的意图:
<receiver android:directBootAware="true" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" android:name=".NotificationReceiver">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" …Run Code Online (Sandbox Code Playgroud) 我正在使用 firebase 云功能在我的应用程序中显示通知,并且工作完美,我面临的唯一问题是当应用程序关闭或在后台通知不显示弹出时。应用程序中使用了平视通知,我确实收到了通知,但通知不会像应用程序位于前台时那样弹出。我已将通道和通知的优先级设置为高,但它仍然不起作用。
我的服务等级:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message"));
Intent intent = new Intent(this, WebViewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
String channelId = "Default";
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.app_logo)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true).setContentIntent(pendingIntent)
.setDefaults(DEFAULT_SOUND | DEFAULT_VIBRATE)
.setPriority(Notification.PRIORITY_MAX);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_HIGH);
channel.setShowBadge(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
manager.createNotificationChannel(channel);
}
manager.notify(0, builder.build());
}
Run Code Online (Sandbox Code Playgroud)
显现
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" …Run Code Online (Sandbox Code Playgroud) android android-notifications firebase firebase-cloud-messaging
我的代码曾经可以工作。它做了:
import iid from '@react-native-firebase/iid';
...
tokenDevice = await iid().getToken();
Run Code Online (Sandbox Code Playgroud)
但现在,我明白了
类型错误:(0, _iid.default) 不是函数。(在“(0,_iid.default)()”中,“(0,_iid.default)”未定义)
看来我的代码无法再导入“@react-native-firebase/iid”了。此外,其他 firebase 软件包的版本为 12+,软件包 iid 停留在 11.5,并且 React-native firebase 文档不再引用 iid https://rnfb-docs.netlify.app/reference
我该怎么做才能让我的设备令牌向特定手机发送消息?
推送通知适用于 Android,但不适用于 iOS。我已经在设备上进行了测试并通过测试飞行,因为不支持模拟器
我已经完成了 iOS 所需的额外设置。
以下是我的 package.json 文件中的相关信息
包.json
"name": "####",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-native-community/async-storage": "*",
"@react-native-community/masked-view": "*",
"@react-native-firebase/analytics": "*",
"@react-native-firebase/app": "*",
"@react-native-firebase/auth": "*",
"@react-native-firebase/firestore": "*",
"@react-native-firebase/messaging": "*",
"prop-types": "*",
"react": "16.13.1",
"react-dom": "^17.0.2",
"react-native": "0.63.4",
"react-native-fbsdk": "*",
"react-native-gesture-handler": "*",
"react-native-reanimated": "^1.0.0-alpha",
"react-native-render-html": "*",
"react-native-safe-area-context": "*",
"react-native-screens": "*",
"react-navigation": "^4.4.4",
"react-navigation-drawer": "^2.7.1",
"react-navigation-stack": "^2.10.4",
"react-navigation-tabs": "^2.11.1",
"typescript": "^4.2.4"
}, …Run Code Online (Sandbox Code Playgroud) ios react-native firebase-cloud-messaging react-native-firebase
firebase ×6
android ×4
flutter ×2
ios ×2
javascript ×2
react-native ×2
flutter-web ×1
java ×1
node.js ×1
postman ×1