我按照指南进行 *** 作.关于函数onNotificationopen(),如doc of the plugin中所述:
App is in background:
User receives the notification message in its device notification bar
User taps the notification and the app opens
User receives the notification data in the JavaScript callback
如果应用程序已关闭(不在后台),如果我发送推送通知,它会:
User receives the notification message in its device notification bar
然后,我点击面板中显示所有通知的通知,应用程序加载并打开.
如果应用程序处于后台,则以下功能会在应用程序占据屏幕前景时触发某些事件:
Firebase.onNotificationopen().subscribe( (res) => { console.info(res)},(err) => { console.info(err)},() => {console.log("completed)});
但是当应用程序关闭时,似乎上面的这个功能没有设置为在应用程序开启时运行.因此,通过点击通知面板中显示的通知,不会发现应用程序已打开.
这是正常的:如果是,是否有文件解释为什么在某处;是否还有另一种方法可以通过事件检测到已经点击通知消息以将应用程序从OFF打开到ACTIVE?如果没有,人们会知道我的错误是什么吗?
解决方法 必须在您自己的代码中的某处处理推送通知(如深层链接) – 在某个地方您需要确定通知打开的活动以及在这种情况下会发生什么.因此,您无法将其推迟到Firebase来为您检测.当应用程序停止运行时,单击推送通知会将带有收到数据的Intent发送到您的应用程序.这是你可以处理它的意图(例如在onStart / Resume()中).如果您在应用程序从通知启动时记录可用的意图,您将看到它包含类似以下内容的内容:
Intent { act=androID.intent.action.MAIN cat=[androID.intent.category.LAUNCHER] flg=0x10000000 pkg=com.my.package cmp=com.my.package/.MyMainActivity (has extras) }Extras { Google.sent_time > 1490275998196,from > 9994599943,Google.message_ID > 0:14902799999965%346177c211bbbb7c2,collapse_key > com.my.package }
这意味着你可以做类似的事情
if (getIntent() != null && getIntent().getExtras() != null) { //IDentify whether this was a push notification intent if (getIntent().getExtras().get("Google.message_ID") != null) { //Here you can do the same things you do when opened from background console.log("completed""); }}总结
以上是内存溢出为你收集整理的Cordova-Plugin-Firebase当应用从OFF变为ACTIVE时,onNotificationOpen()在Android上不起作用全部内容,希望文章能够帮你解决Cordova-Plugin-Firebase当应用从OFF变为ACTIVE时,onNotificationOpen()在Android上不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)