- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 react-native-firebase@4.2.0用于推送通知。
当应用程序在屏幕上打开时,我会通过 onNotification
收到通知,并按照我的代码的预期收到警报。
问题 1当应用程序在后台(未被杀死)时,我会在状态栏中收到通知,但在点击它时,它会被关闭并且应用程序不会打开。
我在 android logcat 中也遇到了这个错误:
06-21 17:26:03.892 5926 8672 D RNFMessagingService: onMessageReceived event received
06-21 17:26:03.913 5926 8600 E ReactNativeJS: No task registered for key RNFirebaseBackgroundMessage
--------- beginning of crash
06-21 17:26:03.932 5926 8601 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
06-21 17:26:03.932 5926 8601 E AndroidRuntime: Process: com.mycustomapp, PID: 5926
06-21 17:26:03.932 5926 8601 E AndroidRuntime: com.facebook.react.common.JavascriptException: No task registered for key RNFirebaseBackgroundMessage, stack:
06-21 17:26:03.932 5926 8601 E AndroidRuntime: startHeadlessTask@57242:24
06-21 17:26:03.932 5926 8601 E AndroidRuntime: __callFunction@4106:49
06-21 17:26:03.932 5926 8601 E AndroidRuntime: <unknown>@3876:31
06-21 17:26:03.932 5926 8601 E AndroidRuntime: __guardSafe@4068:13
06-21 17:26:03.932 5926 8601 E AndroidRuntime: callFunctionReturnFlushedQueue@3875:21
06-21 17:26:03.932 5926 8601 E AndroidRuntime:
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:56)
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:40)
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374)
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:790)
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
06-21 17:26:03.932 5926 8601 E AndroidRuntime: at java.lang.Thread.run(Thread.java:764)
06-21 17:26:03.938 590 590 E SELinux : avc: denied { find } for service=opdiagnose pid=5926 uid=10238 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:opdiagnose_service:s0 tclass=service_manager permissive=0
06-21 17:26:03.939 590 590 E SELinux : avc: denied { find } for service=opdiagnose pid=5926 uid=10238 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:opdiagnose_service:s0 tclass=service_manager permissive=0
06-21 17:26:03.939 5926 8601 W OPDiagnose: getService:OPDiagnoseService NULL
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: Error while parsing timestamp in GCM event
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: java.lang.NumberFormatException: s == null
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: at java.lang.Integer.parseInt(Integer.java:570)
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: at java.lang.Integer.parseInt(Integer.java:643)
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: at com.google.firebase.messaging.zzb.zzb(Unknown Source:81)
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: at com.google.firebase.messaging.zzb.zzc(Unknown Source:2)
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: at com.google.firebase.messaging.FirebaseMessagingService.zzd(Unknown Source:353)
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: at com.google.firebase.iid.zzg.run(Unknown Source:26)
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:7)
06-21 17:26:03.946 5926 8672 W FirebaseMessaging: at java.lang.Thread.run(Thread.java:764)
问题 2当应用程序被终止或未启动时,我在我的 android logcat 中收到:
W GCM : broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.mycustomapp (has extras) }
就是这样。状态栏或任何内容中都没有推送通知。
这些是在我的 AndroidManifest.xml 中添加的服务:
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
应用启动时调用的函数:
firebase.messaging().hasPermission()
.then(enabled => {
if (enabled) {
// permissions granted
} else {
// permissions not granted
}
});
firebase.messaging().getToken()
.then(fcmToken => {
if (fcmToken) {
// user has a device token
console.log(fcmToken);
} else {
// user doesn't have a device token yet
}
});
firebase.notifications().getInitialNotification()
.then((notificationOpen: NotificationOpen) => {
if (notificationOpen) {
// App was opened by a notification
// Get the action triggered by the notification being opened
// Get information about the notification that was opened
}
});
this.onTokenRefreshListener = firebase.messaging().onTokenRefresh(fcmToken => {
// Process your token as required
console.log(fcmToken);
});
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification: Notification) => {
// Process your notification as required
// ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
console.log("onNotificationDisplayed", notification);
});
this.notificationListener = firebase.notifications().onNotification((notification: Notification) => {
// Process your notification as required
Alert.alert(
notification.title,
notification.body,
[
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{ cancelable: true }
)
});
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
// Get the action triggered by the notification being opened
const action = notificationOpen.action;
// Get information about the notification that was opened
const notification: Notification = notificationOpen.notification;
console.log("onNotificationOpened", notification);
});
this.messageListener = firebase.messaging().onMessage((message: RemoteMessage) => {
// Process your message as required
console.log("onMessage", message);
});
这是我的bgMessaging.js:
import { AppRegistry } from 'react-native';
import firebase from 'react-native-firebase';
// Optional flow type
import type { RemoteMessage } from 'react-native-firebase';
export default async (message: RemoteMessage) => {
// handle your message
console.log("RemoteMessage", message);
return Promise.resolve();
}
AppRegistry.registerHeadlessTask('AppBackgroundMessage', () => bgMessaging);
如果相关,我会使用 react-native-navigation
。如果您需要任何其他信息,请发表评论。
最佳答案
The headless task must be registered as RNFirebaseBackgroundMessage.
更改代码:
AppRegistry.registerHeadlessTask('AppBackgroundMessage', () => bgMessaging);
到
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessaging);
我希望你已经完成了this 4 steps在后台列出 FCM 消息。
关于android - native react -应用程序被杀死/未启动时未收到通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50969267/
如何在终止父进程时关闭我的子文件描述符? 我创建了一个执行以下操作的程序: 派生 2 个子进程。 进程 1 是一个读取器。它从 STDIN_FILENO 读取并使用 scanf/printf 写入 S
我试着写了一个小的暴力破解程序。密码程序在密码正确时返回 1,错误时返回 0。所以它很简单。 在 bruteforce 程序中,我使用 createprocess() 调用 pw 程序。 我的问题是,
谁能帮我解释一下我从一本书中得到的这个脚本。练习是编写一个名为 killalljobs 的脚本来终止所有后台作业。 为此给出的代码是: kill "$@" $( jobs -p) 我确定我在这里真
我正在开发一个包含许多库的应用程序。后来我注意到有几次应用程序进程在关闭应用程序后仍在耗尽 CPU。 我先终止了进程,但它继续运行。我卸载了该应用程序 - 但它仍然存在! (使用开发人员选项中的“显示
有没有办法在无人机完成或超时之前杀死它? 无人机的默认超时时间为 6 小时 ( https://github.com/drone/drone/blob/master/cmd/drone/drone.g
我有几个自动启动的菜单栏程序/进程/应用程序。我希望能够使用单个命令或脚本将它们全部关闭;有时带宽受到限制或受限,它们会导致(或至少导致)旋转的沙滩球死亡。目前,我手动关闭每一个。 关注 answer
当我阅读 learnyousomeerlang.com 上的一篇文章时,我有一个问题。 http://learnyousomeerlang.com/errors-and-processes 它说: E
有什么方法可以通过 OpenCL API 终止正在运行的 OpenCL 内核吗?我没有在规范中找到任何内容。 我能想出的唯一解决方案是 1) 定期检查内核中的标志,当主机希望内核停止时写入该标志,或
我已经对套接字(使用fsockopen()和stream_socket_client())和cURL进行了一些测试,以强制关闭连接(TCP/HTTP)。但是,没有运气。 无论我使用的是1毫秒的超时时间
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
我以不太优雅的方式杀死了 IRB 提示符(从 heroku run irb 开始),现在我有一个僵尸进程,但我似乎无法杀死它: Process State Co
致kill background process inside Codeship我们需要使用以下命令: #!/bin/bash nohup bash -c "YOUR_COMMAND 2>&1 &"
我第一次在这里发帖,因为我在互联网上找不到干净的解决方案。 我的目标很简单,我需要创建 一个 后台操作 (goroutine 或进程或其他...)我可以 正确杀死 (不要留在后台)。 我尝试了很多事情
我有一个进程调用: p=multiprocessing.Process(target=func_a) 然后func_a启动一个子进程: subprocess.Popen(["nc", "-l", "-
我正在运行一个基本上运行一堆服务器以进行本地测试的脚本。 这些 jar 在不同的 screen 中运行,因为它们需要独立地接受键盘输入。为此,我使用了 screen 。 command1="java
我有一个用 java 编写的应用程序,它在 Unix 上运行,并在启动时启动两个子进程(通过 Runtime.getRuntime().exec())。如果应用程序由于某种原因崩溃,子进程不会被终止。
我想要像 Pushbullet、SmartLockScreen 或 WhatsApp 那样独立运行的服务,它正在等待某个事件的发生。我已经尝试过前台服务,在 onStartCommand 中返回 ST
强制停止应用程序后,是否可以在 Android 应用程序中获取位置更新。在 IOS 中,如果我们强制停止应用程序,则有可能获得位置更新,以类似的方式,是否有任何服务可以为在 android 中被杀死的
我正在调查是否有任何方法可以防止 android 服务因未捕获的异常而被杀死。 我们有 10 个 UI 应用程序与 5-6 个服务通信。该平台是Android 2.2。 由于不可预见的情况,服务中的某
我刚刚将我的 javascript 转移到 jQuery 来实现简单的 AJAX 功能。不过,我尝试将灯箱插件与 jQuery 结合使用,因为我想保留相同的功能,但不想包含 10 个不同的库。如果我删
我是一名优秀的程序员,十分优秀!