简体   繁体   中英

Receiving only default message in Android GCM using Amazon SNS

I am implementing a notification service on the server, to push out notifications to both Android and Iphones.

The problem I am having at the moment is that the Android device which I am testing on, is only receiving the default message.

My code is as follows :-

Main Program

string smsMessageString = "{\"default\": \"This is the default message which must be present when publishing a message to a topic. The default message will only be " +
                                                    " used if a message is not present for one of the notification platforms.\"," +
                                    "\"APNS\": {\"aps\": {\"alert\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}," +
                                    "\"GCM\": {\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}," +
                                    "\"ADM\": {\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}}";


        var smsMessage = new SmsMessageObj
        {
            smsMessageSubject = "Test Message", 
            smsMessageBody = smsMessageString
        };

        snsClient.SendPush(endpointArn, smsMessage);

and the SendPush is as follows :-

    public void SendPush(string endpointArn, SmsMessageObj msg)
    {
        if (string.IsNullOrEmpty(endpointArn))
            throw new Exception("Endpoint ARN was null");

        var pushMsg = new PublishRequest
        {
            Message = msg.smsMessageBody,
            MessageStructure = "json",
            Subject = msg.smsMessageSubject,
            TargetArn = endpointArn
        };


        _client.Publish(pushMsg);

    }

Do I need to include anything more so that I can get the "correct" Android notification?

Do I need anything in the app.config?

Thanks for your help and time

I have resolved this question. All I needed to do was to stringify the Json. Maybe it will help someone else in the future. So what I did was :-

        var apns_Json = "{\"aps\": {\"alert\": \"Check out these awesome deals_Apple!\",\"url\": \"www.amazon.com\"}}";
        var gcm_Json = "{\"data\": {\"message\": \"Check out these awesome deals_Google!\",\"url\": \"www.amazon.com\"}}";
        var adm_Json = "{\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}";

        string smsMessageString = "{\"default\": \"This is the default message which must be present when publishing a message to a topic. The default message will only be " +
                                        " used if a message is not present for one of the notification platforms.\"," +
                        "\"APNS\": " + JsonConvert.ToString(apns_Json) + "," +
                        "\"GCM\": " + JsonConvert.ToString(gcm_Json) + "," +
                        "\"ADM\": " + JsonConvert.ToString(adm_Json) + "}";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM