android - 当应用程序在后台时,如何将收到的来自 Firebase 远程消息的推送通知存储到 sqlite 数据库中?
问题描述
我已经尝试过此代码。但即使我无法在 logcat 中打印,我也无法处理远程消息。
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.d("token",s);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getData().size() > 0){
Log.d("remoteMsg",remoteMessage.getData().toString());
String title,message,Id;
Map data = remoteMessage.getData();
title = data.get("title").toString();
message = data.get("body").toString();
Id = data.get("NotifyId_Enc").toString();
try {
JSONObject json = new JSONObject(remoteMessage.getData().toString());
handleDataMessage(json);
Log.d("fol", String.valueOf(json));
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
Intent intent = new Intent(this,MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
Uri soundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(message);
notificationBuilder.setContentText(Id);
notificationBuilder.setSound(soundUri);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
}else {
Log.d("remoteMsg","not working");
}
}
我正在从 .net Web 服务器发送通知并接收 fcm 远程消息,但我无法处理它。在 android 设备中收到推送通知。
我的问题是关于如何处理远程消息..仅此而已
解决方案
推荐阅读
- java - 获取泛型类的.class对象
- node.js - 在 Google Cloud Functions 上使用 Google Sheets API,getClient() 不起作用,函数超时
- adaptive-cards - 将操作按钮设为蓝色
- laravel-5 - 我试图查看我的编辑表单。但它为更新路线提供了路线缺失的参数
- python - Python:Kivy:如何对齐标签本身和文本框?
- python - Python:lxml 并非一直在读取元素文本
- asp.net - 在 Web 应用程序中应用缓存技术的最佳实践/设置是什么?
- c# - 尝试打印覆盖的 ToString() 方法时,C# 无法从“方法组”转换为“布尔”
- wiremock - Wiremock 服务器在调用时返回 HTTP ERROR 500
- javascript - 在 pdf.js 中完成加载之前渲染 pdf