我正在尝试在推送通知中添加自定义声音。我已在客户端(颤动)的后台处理程序中添加了 showNotification,但现在当应用程序位于后台或终止时,我会收到重复的通知,一个带有默认声音,另一个带有我的自定义声音。谁能告诉我如何停止显示默认后台通知?
我有一个用 flutter 制作的 Android 应用程序,在我使用过的旧版本中,firebase_messaging它要求我将MainActivity文件更改为Application下面提到的一些编辑,以便能够处理后台消息。当时效果很好。
这是旧Application文件:
package com.deliveryrunner.vendor;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
FirebaseCloudMessagingPluginRegistrant.registerWith(registry);
}
}
Run Code Online (Sandbox Code Playgroud)
现在升级到最新版本的 flutter 后,firebase_messaging他们在文档中提到我不再需要这个,我可以恢复正常MainACtivity,我就这样做了。这是MainActivity文件:
package com.deliveryrunner.vendor
import io.flutter.embedding.android.FlutterActivity
class MainActivity : FlutterActivity() {}
Run Code Online (Sandbox Code Playgroud)
请注意,AndroidManifest.xml每当我更改文件时,我都会更改条目:
<application
android:name=".Application"
Run Code Online (Sandbox Code Playgroud)
<application
android:name=".MainActivity"
Run Code Online (Sandbox Code Playgroud)
最后,升级后,每当我运行应用程序时,我都会收到此错误:
E/AndroidRuntime(14596): FATAL EXCEPTION: main
E/AndroidRuntime(14596): …Run Code Online (Sandbox Code Playgroud) 在 GetX 状态管理的帮助下,我已将 Firebase Cloud Messaging 集成到我的 Flutter 移动应用中。我还使用 Laravel 和 Firebase Admin SDK 向我的应用程序发送通知。
\n该通知在前台状态和后台状态(已暂停)下都运行良好。当我单击应用程序处于终止状态(应用程序关闭)的通知时,问题就开始了。我是否必须在启动画面和主页之间设置延迟?
\n我已经尝试这样做但仍然出现错误
\n//open notif content from terminated state of the app\nFirebaseMessaging.instance.getInitialMessage().then((message) {\n if (message != null) {\n print('TERMINATED');\n if (FirebaseAuth.instance.currentUser != null) {\n final redirectRoute = message.data['route'];\n if (redirectRoute != null) { \n //adding delay here since my splashscreen have the same delay \n Future.delayed(const Duration(seconds: 6));\n bottomnavbarController.updateIndex(int.parse(redirectRoute));\n }\n } else {\n Get.offAllNamed(Routes.LOGIN);\n }\n }\n});\nRun Code Online (Sandbox Code Playgroud)\n我收到这个错误
\nUnhandled Exception: \nYou are …Run Code Online (Sandbox Code Playgroud) 我正在设法通过 Django 将 FCM 通知发送到我的应用程序。这是我的推送通知功能:
import firebase_admin
from firebase_admin import credentials, messaging
cred = credentials.Certificate("service-key.json")
firebase_admin.initialize_app(cred)
def send_push(title, msg, registration_token, dataObject=None):
try:
message = messaging.MulticastMessage(
notification=messaging.Notification(
title=title,
body=msg,
),
data=dataObject,
tokens=registration_token,
)
response = messaging.send_multicast(message)
except messaging.QuotaExceededError:
raise f'Exceeding FCM notifications quota'
Run Code Online (Sandbox Code Playgroud)
现在,我将在视图内发送通知:
class AdminChangeRole(viewsets.Viewset):
serializer_class = SomeSerializer
permission_classes = [IsAdminOnly]
def post(self, request, *args, **kwargs):
# code that will change the role of a user
send_push("Role changed", f"You role was set to {self.role}", fcm_registration_token)
# return Response
Run Code Online (Sandbox Code Playgroud)
现在,在序列化器中发布一些数据并保存它之后。我希望向用户发送通知。但是,我想知道我是否正确处理了这个问题,包括并行 2500 …
python django firebase python-asyncio firebase-cloud-messaging
我正在尝试使用 Firebase 消息服务向Android 12 设备发送推送通知。当我尝试从nodeJs发送FCM时,不会调用onMessageReceived。我尝试从 Firebase 控制台发送 FCM,但即使应用程序位于后台,应用程序也不会显示任何通知或错误。我已经在android 11和android 10中测试了这个应用程序,两者都工作正常。
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/icon_round"
android:supportsRtl="true"
android:theme="@style/Theme.MobileSMSService"
android:usesCleartextTraffic="true">
<service
android:name=".helper.MessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/sms_icon_foreground" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/purple_700" />
</service>
</application>
Run Code Online (Sandbox Code Playgroud)
消息服务.java
public class MessagingService extends FirebaseMessagingService {
private static final String CHANNEL_ID = "FCM";
private static final String TAG = "MessagingService";
whatsappMessageService messageService;
@Override
public void onNewToken(@NonNull String s) {
super.onNewToken(s);
JSONObject …Run Code Online (Sandbox Code Playgroud) 在 Firebase 推送通知中,有效负载可以是“通知”或“有效负载”类型,但它们是否到达(或不到达)取决于应用程序是否处于后台以及其他详细信息。请澄清它们。
我正在订阅一个主题并使用 Firebase 控制台/云消息传递推送通知;在 Android 上,一切正常。在 iOS 上,当应用程序处于前台/后台/终止(配置文件模式)时,我会在通知中心收到通知
问题: iOS 应用程序图标上没有出现徽章。
我一直在检查不同的文章和质量保证,但仍然没有解决方案。任何可以帮助我进行更多调查的线索或想法都可能解决这个问题,我们将不胜感激。
已尝试 >在调试和配置文件模式下运行,使用配备 iOS 15 和 iPhone Xs 的 iPhone 12 pro
我也尝试过flutter_app_badger仍然没有得到任何徽章计数。
在我的main档案中;
Future<void> _messageHandler(RemoteMessage message) async {
print('background message ${message.notification!.body}');
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
).then((value) {
FirebaseMessaging.onBackgroundMessage(_messageHandler);
});
runApp(MyApp());
}
Run Code Online (Sandbox Code Playgroud)
在initState我的应用程序的第一个屏幕中;
@override
void initState() {
super.initState();
PushNotify().init(context);
messaging = FirebaseMessaging.instance;
messaging.subscribeToTopic("messaging");
messaging.setForegroundNotificationPresentationOptions(
alert: true, // Required to display a heads up notification
badge: true,
sound: …Run Code Online (Sandbox Code Playgroud) push-notification ios flutter firebase-cloud-messaging firebase-notifications
我在我的游戏控制台中收到以下错误,没有任何堆栈跟踪(在 android 7 和 10 上)。
Broadcast of Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000010 pkg=com.mycompany.myapp cmp=com.mycompany.myapp/com.google.firebase.iid.FirebaseInstanceIdReceiver (has extras) }
Run Code Online (Sandbox Code Playgroud)
使用的 Firebase 版本,
implementation 'com.google.firebase:firebase-iid:21.1.0'
implementation 'com.google.firebase:firebase-messaging:23.0.6'
Run Code Online (Sandbox Code Playgroud)
我不知道我的代码的哪一部分到底导致了这个错误,我发布了负责上传到FCM token我的服务器的代码。
我的Firebase消息服务,
@Override
public void onNewToken(@NonNull String s) {
super.onNewToken(s);
new TokenUploader().setFcmToken();//send to server
}
Run Code Online (Sandbox Code Playgroud)
TokenUploader类
//this function is called from MyFirebaseMessagingService and MainActivity
public void setFcmToken() {
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(task -> {
if (task.isSuccessful()) new Thread(() -> pushFcmToken(task.getResult())).start();
else if (task.getException() != null)
new Thread(() -> pushFcmToken(task.getException().getMessage())).start();
});
}
//push token to server
private …Run Code Online (Sandbox Code Playgroud) 我正在尝试集成 fcm 以进行推送通知,并且我们还使用一些 aws 服务进行开发。我想了解\xe2\x80\x99s 将 aws sns 与 fcm 结合使用,因为我做了一些研究,发现我们可以使用 fcm 发送推送通知而不需要 aws sns 那么使用 aws sns 有什么优势。
\namazon-web-services amazon-sns firebase firebase-cloud-messaging
我已按照文档中的描述配置了 Firebase Cloud Messaging (FCM),并且它按预期工作。iOS 和 Android 设备会收到通知,如果点击通知,应用程序就会打开。
我想在点击通知并打开应用程序时显示一个警报对话框,因为如果 iOS 上的通知菜单超过一定数量的字符,则不会显示整个通知正文内容。
我尝试添加到链接文档中提供的代码,如下所示,但showDialog需要一个context. 由于这些方法是在main.dart文件中定义的,因此没有可用的上下文?
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FirebaseMessaging messaging = FirebaseMessaging.instance;
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
if (message.notification != null) {
showDialog(
context: context, // suggests importing dart.js
// this.context => "invalid reference to 'this' expression"
builder: (_) …Run Code Online (Sandbox Code Playgroud) firebase ×6
flutter ×5
android ×4
amazon-sns ×1
django ×1
flutter-getx ×1
ios ×1
java ×1
python ×1