- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个使用 firebase 云消息传递来接收通知的 Android 应用程序,我将通知和数据从 fcm 发送到我的应用程序,当我的应用程序处于状态时单击通知栏时,我想根据 fcm 的数据执行操作背景,我使用下面的代码,当应用程序在前台时可以正常工作,但在后台它只是打开应用程序而不执行任何操作:
class MyFirebaseMessagingService : FirebaseMessagingService() {
val TAG = "FirebaseMessagingService"
var count = 0
@SuppressLint("LongLogTag")
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if (remoteMessage.data != null && remoteMessage.data.isNotEmpty()) {
val id = remoteMessage.data["id"].toString()
val activityName = remoteMessage.data["view"].toString()
val intent = Intent(this, NewsDetailesActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
NewsDetailesActivity.currentNewId = id
startActivity(intent)
showNotification(remoteMessage.notification?.title, remoteMessage.notification?.body,activityName,id)
}
}
private fun showNotification(title: String?, body: String?,activityName:String,id:String?) {
var intent = Intent(this, NewsDetailesActivity::class.java)
if (activityName == "news")
{
intent = Intent(this, NewsDetailesActivity::class.java)
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
NewsDetailesActivity.currentNewId = id!!
val pendingIntent = PendingIntent.getActivity(
this, 0, intent,
PendingIntent.FLAG_ONE_SHOT
)
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this, "channelId")
.setSmallIcon(R.drawable.logo_orang)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setSound(soundUri)
.setContentIntent(pendingIntent)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(count, notificationBuilder.build())
count += 1
}
}
如何修改我的应用程序以在后台运行?
最佳答案
始终在通知 API 调用中发送数据对象像这样:
{
"data" : {
"body" : "Watch Live Footlball Streaming online & stay updated with fastest live match scores on Hotstar",
"content_available" : true,
"title" : "Brazil vs. Denmark",
"isScheduled":false,
"scheduledTime":"2020-03-03 12:20:00",
"stationCode":"PNB",
"groupId":2
},
"to" : "epGANq1gDpE:APA91bHEuHS_QRILwI9GJ-x8Sz4DKjHRN0KX23R5TGx9HyRAN8caghmakMSnRavOf4Qwnmni3ByVRndvMjmMvfQnVt-2g6AgI5OB1-0vK3HQWDdhAjb155KWnYLXgEn763hSSbPX7tFm",
"priority" : "high"
}
此外,请检查此示例是否在后台运行。 https://github.com/googlecodelabs/android-kotlin-notifications-fcm
关于java - android:根据FCM通知的数据采取行动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57347022/
在 Catalyst我正在尝试转发一个私有(private)行动来做一些工作。这是函数定义: sub get_form :Private :Args(1) { my ($self, $c, $ty
public class SimpleHTTPRequest { String envelope1="" + ""+ ""+ ""+ "ghjghj"+
我有一些返回 Promise 的 JavaScript 函数。我使用 .then 来处理从这些函数返回的数据。但是,下面的代码是否保证了顺序? result2 会在 result 之后处理吗? con
我有这样的类层次结构 public abstract class CalendarEventBase{} public class TrainingEvent : CalendarEventBase{
我有一个问题:我需要创建一个可以从 javascript 调用的网络服务(在 C# 中),该服务返回一个在(它是一个 excel)中生成的文件,并且在 javascript 中返回一个新文件,打开一个
我正在向我的 UITableViewCell 添加自定义按钮。在该按钮的操作中,我想调用 showAlert: 函数并希望在该方法中传递单元格标签。 如何在 showAlert 方法中传递参数:act
我正在尝试推送到 harbor registry 2.2。它与 ssl 一起工作,并且存储在本地安装的 NFS 共享上。我得到的错误是:未经授权访问存储库:测试/ flask ,操作:推送:未经授权访
我正在尝试推送到 harbor registry 2.2。它与 ssl 一起工作,并且存储在本地安装的 NFS 共享上。我得到的错误是:未经授权访问存储库:测试/ flask ,操作:推送:未经授权访
无论我如何尝试编写 Action 测试,这个错误都会困扰我一段时间,它给了我这个: “操作可能没有未定义的“类型”属性。您是否拼错了常量?操作:{}" 但如果我控制台记录我正在尝试测试的操作,它会打印
我是一名优秀的程序员,十分优秀!