我正在使用 Firebase 将通知从服务器推送到特定的 Android 设备。我想获取收到通知的时间(设备的本地时间而不是服务器时间)。我怎样才能得到它?
因为我必须显示一个与该时间相关的计时器,所以这就是为什么我需要在该设备上收到通知时的确切时间。
time android push-notification firebase firebase-cloud-messaging
我一直在到处搜索,但就是不知道如何获取正在运行的 Android 应用程序的当前(顶部)活动。
\n\n好吧,我的情况是,当应用程序位于前台并且调用\xe2\x80\x8bonMessageReceived(FirebaseMessagingService 的子类)时,我收到了 Firebase Cloud Messaging Data 负载。我需要找出用户正在查看的屏幕,然后决定关闭(finish())它或发送一些数据(通过 Extras / Bundle)并刷新视图。
\n\n那么,我如何找出当前的视图/活动是什么并讨论或发送一些数据并导致视图刷新?
\n\n谢谢!
\nandroid push-notification firebase firebase-cloud-messaging android-push-notification
The problem is as stated above. If I try to subscribe to a push notification via the url: https://iid.googleapis.com/iid/v1/{token}/rel/topics/{topic}, I always get the following response: {"error":"InvalidToken"}
I have tried using both GET and POST methods but still the same response.
I have checked if the Token is a valid token by using the following url: https://iid.googleapis.com/iid/info/{token} which return the correct data like this:
{
"application": "com.chrome.windows",
"subtype": "wp:http://localhost/#2A58747F-DEF7-4C55-8073-126B2D168-V2",
"authorizedEntity": "856365479457",
"platform": "WEBPUSH"
}
Run Code Online (Sandbox Code Playgroud)
If my token is valid, then …
在与 Firebase Cloud Messaging 斗争了几个小时后,我发现了问题并想在这里发帖,因为我之前找不到答案。
我的问题是:我正在使用 Firebase Cloud Messaging,但在订阅主题和接收消息时遇到很多麻烦。当尝试直接向设备发送消息时,我经常会收到“未注册”错误,并且在订阅主题时无法订阅主题错误 Domain=com.google.fcm Code=0“(null)”。
我今天已经升级了我所有的 firebase 软件包,我不得不升级到版本 8.0.0-dev.13 以进行 firebase 消息传递,即使由于依赖性问题它仍在开发中。在 Application.Java 中,我有:
package com.halloglobal.flutterapp.hallo;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
import io.flutter.view.FlutterMain;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@override
public void registerWith(PluginRegistry registry) {
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}
Run Code Online (Sandbox Code Playgroud)
过去运行良好,但现在使用这个新版本,我收到此错误:注意:使用 -Xlint:deprecation 重新编译以获取详细信息。/Users/hallo/Documents/HalloMonoRepo/hallo/android/app/src/main/java/com/halloglobal/flutterapp/hallo/Application.java:7: 错误:包 io.flutter.plugins.firebasemessaging 不存在 import io .flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService; ^ /Users/hallo/Documents/HalloMonoRepo/hallo/android/app/src/main/java/com/halloglobal/flutterapp/hallo/Application.java:8: 错误:包 io.flutter.plugins.firebasemessaging 不存在导入io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
我需要如何更改我的 Application.java 才能使用新版本?
我尝试将 Firebase Messaging 安装到旧的 Flutter 项目,但收到此错误消息
因为 firebase_messaging >=7.0.3 <8.0.0-dev.7 取决于 firebase_core ^0.5.0+1 和 firebase_admob >=0.9.1 <0.10.0-dev.1 取决于 firebase_core ^0.4.2+1,firebase_messaging >=7.0.3 <8.0.0-dev.7 与 firebase_admob >=0.9.1 <0.10.0-dev.1 不兼容。所以,因为 AppName 依赖于 firebase_admob ^0.9.3+2 和 firebase_messaging ^7.0.3,版本解析失败。
pubspec.yaml 文件
cupertino_icons: ^0.1.3
sqflite: ^1.2.1
path_provider: ^1.6.5
flutter_local_notifications: ^1.2.1
firebase_auth: ^0.15.5+2
google_sign_in: ^4.1.4
network_to_file_image: ^2.2.8
shared_preferences: ^0.5.6+2
firebase_database: ^3.1.3
url_launcher: ^5.4.2
share: ^0.6.3+6
firebase_in_app_messaging: ^0.1.1+3
auto_direction: ^0.0.4+1
sliding_up_panel: ^1.0.0
draggable_scrollbar: ^0.0.4
firebase_admob: ^0.9.3+2
provider: ^4.3.2
pdf: ^1.10.0
printing: ^3.5.0
flutter_sms: ^2.0.0+1
timeline_tile: ^1.0.0
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?
所以,我在我的flutter应用程序上设置了 FCM 通知。它的工作原理既适用于Android两个在iOSdebug和release模式。
当我创建一个版本apk并在我的手机上测试它时,通知会起作用。但是当我上传appbundle到 Play 商店时,我从 Play 商店下载的版本通知不起作用。该getToken方法返回null,关于为什么会出现这种情况的任何想法?
android push-notification firebase flutter firebase-cloud-messaging
在我的应用程序中将 Xamarin.Azure.NotificationHubs.Android Nuget 从古老的 0.6 升级到 1.1.4.1(这还涉及从支持库升级到 AndroidX)后 - 没有 Azure 通知中心和 FireBase Nuget(以及使用它们的注释代码),一切正常. 使用这些 Azure/FCM NuGets 启动应用程序时出现异常:
[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] Process: com.taphome.android.next, PID: 12930
[AndroidRuntime] java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/datatransport/runtime/ExecutionModule_ExecutorFactory;
[AndroidRuntime] at com.google.android.datatransport.runtime.DaggerTransportRuntimeComponent.initialize(DaggerTransportRuntimeComponent.java:75)
[AndroidRuntime] at com.google.android.datatransport.runtime.DaggerTransportRuntimeComponent.<init>(DaggerTransportRuntimeComponent.java:66)
[AndroidRuntime] at com.google.android.datatransport.runtime.DaggerTransportRuntimeComponent.<init>(DaggerTransportRuntimeComponent.java:36)
[AndroidRuntime] at com.google.android.datatransport.runtime.DaggerTransportRuntimeComponent$Builder.build(DaggerTransportRuntimeComponent.java:109)
[AndroidRuntime] at com.google.android.datatransport.runtime.TransportRuntime.initialize(TransportRuntime.java:78)
[AndroidRuntime] at com.google.firebase.datatransport.TransportRegistrar.lambda$getComponents$0(TransportRegistrar.java:37)
[AndroidRuntime] at com.google.firebase.datatransport.TransportRegistrar$$Lambda$1.create(Unknown Source:0)
[AndroidRuntime] at com.google.firebase.components.ComponentRuntime.lambda$discoverComponents$0(ComponentRuntime.java:132)
[AndroidRuntime] at com.google.firebase.components.ComponentRuntime$$Lambda$1.get(Unknown Source:4)
[AndroidRuntime] at com.google.firebase.components.Lazy.get(Lazy.java:53)
[AndroidRuntime] at com.google.firebase.components.AbstractComponentContainer.get(AbstractComponentContainer.java:27)
[AndroidRuntime] at com.google.firebase.components.RestrictedComponentContainer.get(RestrictedComponentContainer.java:89)
[AndroidRuntime] at com.google.firebase.messaging.FirebaseMessagingRegistrar.lambda$getComponents$0$FirebaseMessagingRegistrar(Unknown Source:43)
[AndroidRuntime] …Run Code Online (Sandbox Code Playgroud) xamarin.android azure-notificationhub firebase-cloud-messaging
当应用程序关闭或在后台时,我试图停止来自 firebase_message 的默认通知。
我想在应用程序关闭时或使用 local_notifications 插件在后台显示自定义通知,它按预期工作,问题存在于发送消息时,应用程序显示相同的通知两次,默认情况下显示 1 个通知,另一个显示自定义通知。
我无法实现停止默认通知。有人能在这里指出我的错误吗?
初始代码来自 firebase 消息传递示例,删除了不必要的片段并添加了自定义通知。
还附上了当前(不良行为)的图像
如前所述,相同的通知显示两次,想要摆脱图像上显示的第一个通知。
这是我的代码:
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'utils/utils.dart';
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print('_firebaseMessagingBackgroundHandler');
Future onDidReceiveLocalNotification(
int? id, String? title, String? body, String? payload) async {
print('onDidReceiveLocalNotification'); …Run Code Online (Sandbox Code Playgroud) 我正在尝试将firebase_messaging包与我的 flutter 应用程序集成。通常它可以正常工作(版本 7.0.3)我正在使用的代码(见下文)但是自从发布了空安全版本我的代码不再工作了。我想知道是否有人可以帮助我找出我做错了什么?
错误导致代码
try {
fcmToken = await _firebaseMessaging.getToken();
} catch (error) {
print(error);
}
Run Code Online (Sandbox Code Playgroud)
错误输出
E/AndroidRuntime( 8942): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/Metadata;
E/AndroidRuntime( 8942): at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin.lambda$getToken$1$FlutterFirebaseMessagingPlugin(FlutterFirebaseMessagingPlugin.java:165)
E/AndroidRuntime( 8942): at io.flutter.plugins.firebase.messaging.-$$Lambda$FlutterFirebaseMessagingPlugin$p8YQXDuFBNIxl8PFaPCQJtYc3sw.call(Unknown Source:4)
E/AndroidRuntime( 8942): at com.google.android.gms.tasks.zzv.run(Unknown Source:2)
E/AndroidRuntime( 8942): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime( 8942): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime( 8942): at java.lang.Thread.run(Thread.java:923)
E/AndroidRuntime( 8942): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.Metadata" on path: DexPathList[[zip file "/data/app/~~uCa7QFzhvu5i_TZpnqat0w==/com.example.****-1cbY-LKuCoOsfZybV-Gq6g==/base.apk"],nativeLibraryDirectories=[/data/app/~~uCa7QFzhvu5i_TZpnqat0w==/com.example.****-1cbY-LKuCoOsfZybV-Gq6g==/lib/x86, /data/app/~~uCa7QFzhvu5i_TZpnqat0w==/com.example.****-1cbY-LKuCoOsfZybV-Gq6g==/base.apk!/lib/x86, /system/lib, /system_ext/lib]]
E/AndroidRuntime( 8942): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
E/AndroidRuntime( 8942): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime( 8942): …Run Code Online (Sandbox Code Playgroud)