У меня есть лямбда-функция, написанная и размещенная на amazon lambda.Ниже приведен код для этой лямбды:
const AWS = require('aws-sdk');
exports.handler = (event, context) => {
console.log("Received event:", JSON.stringify(event, null, 2));
const targetArn = event.TargetArn;
const sns = new AWS.SNS();
const payload = {
default: "some default message",
GCM: {
notification: {
title: "Sample title",
body: "Sample Body"
},
data: {
title: "Sample title",
body: "Sample Body"
}
}
};
const params = {
Subject: "some default subject",
Message: JSON.stringify(payload),
MessageStructure: "json",
TargetArn: targetArn
};
console.log('PUBLISHING', JSON.stringify(params, null, 2));
sns.publish(params, function(err, data) {
console.log('PUBLISHED!');
if (err) {
console.log(err, err.stack);
return {
statusCode: 500,
body: JSON.stringify({error: err})
};
} else {
console.log('SUCCESS!', data);
return {
statusCode: 200,
body: JSON.stringify(data)
};
}
});
};
Теперь, когда я тестирую лямбду, чтобы проверить, получаю ли я push на Android, я не вижу целого сообщения, напечатанного на консоли.Ниже мой код, который я использовал для входа в Android:
public class MyFirebaseMessagingService extends FirebaseMessagingService implements LifecycleObserver {
public static final String ACTION_USER_FEEDBACK = "ACTION_UserFeedback";
public static final String ARG_TITLE = "Title";
public static final String ARG_BODY = "Body";
private static final String TAG = MyFirebaseMessagingService.class.getSimpleName();
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "onMessageReceived() called with: remoteMessage = [" + remoteMessage + "]");
super.onMessageReceived(remoteMessage);
if (remoteMessage.getData() != null) {
for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
Log.d(TAG, "Data: key, " + key + " value " + value);
}
String title = remoteMessage.getData().get("title");
String body = remoteMessage.getData().get("body");
notifyActivity(title, body);
}
if (remoteMessage.getNotification() != null) {
for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
Log.d(TAG, "Notification: key, " + key + " value " + value);
}
}
}
private void notifyActivity(String title, String body) {
Intent intent = new Intent(ACTION_USER_FEEDBACK);
intent.putExtra(ARG_TITLE, title);
intent.putExtra(ARG_BODY, body);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
@Override
public void onNewToken(String token) {
sendRegistrationToServer(token);
}
private void sendRegistrationToServer(String token) {
FCMTokenPreference.storeFCMDeviceToken(this, token);
AWSRegistrationIntentService.start(this);
}
}
Ниже приводится то, что я получаю на консоли при тестировании лямбды:
D / MyFirebaseMessagingService: onMessageReceived () с именемwith: remoteMessage = [com.google.firebase.messaging.RemoteMessage@d9558fe] D / MyFirebaseMessagingService: Data: key, значение по умолчанию, некоторое сообщение по умолчанию
Цель - отправить push-уведомление типа Уведомление , а не Данные
Может кто-нибудь помочь мне с этим?