Android 当收到firebase的通知时,应用程序不断崩溃
我正在尝试使用Firebase消息为我的应用程序添加通知。我正在使用firebase云消息发送通知。我还使用云函数来设置对用户的通知。我现在遇到的问题是,只要是关于接收通知的应用程序,它就会崩溃 这是我的身材,格雷德尔Android 当收到firebase的通知时,应用程序不断崩溃,android,firebase,flutter,push-notification,crash,Android,Firebase,Flutter,Push Notification,Crash,我正在尝试使用Firebase消息为我的应用程序添加通知。我正在使用firebase云消息发送通知。我还使用云函数来设置对用户的通知。我现在遇到的问题是,只要是关于接收通知的应用程序,它就会崩溃 这是我的身材,格雷德尔 def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) {
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.wall"
minSdkVersion 16
multiDexEnabled true
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
apply plugin: 'com.google.gms.google-services'
这是我的云功能
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.onCreateActivityFeedItem = functions.firestore
.document('/feed/{userId}/feedItems/{activityFeedItem}')
.onCreate(async (snapshot, context) =>
{
const userId = context.params.userId;
const userRef = admin.firestore().doc(`users/${userId}`);
const doc = await userRef.get();
const androidNotificationToken = doc.data().androidNotificationToken;
const createActivityFeedItem = snapshot.data();
if(androidNotificationToken)
{
sendNotification(androidNotificationToken, createActivityFeedItem);
}
else
{
console.log("No token for user, can not send notification.")
}
function sendNotification(androidNotificationToken, activityFeedItem)
{
let body;
switch (activityFeedItem.type)
{
case "comment":
body = `${activityFeedItem.username} replied: ${activityFeedItem.commentData}`;
break;
case "like":
body = `${activityFeedItem.username} liked your post`;
break;
case "follow":
body = `${activityFeedItem.username} started following you`;
break;
default:
break;
}
const message =
{
notification: { body },
token: androidNotificationToken,
data: { recipient: userId },
};
admin.messaging().send(message)
.then(response =>
{
console.log("Successfully sent message", response);
})
.catch(error =>
{
console.log("Error sending message", error);
})
}
});
感谢您的帮助。多谢各位