Skip to content
This repository was archived by the owner on Jan 9, 2019. It is now read-only.
This repository was archived by the owner on Jan 9, 2019. It is now read-only.

Receive message when app openning #23

@bakman23

Description

@bakman23

Hi, when I send a message (not notification) to a device how my app is close, The app not receive the message when I open it again. But I receive messages if I send when the app is open.
Is it possible to do that if yes how can I do?
Thanks
PS : my app are register on server and the lifespan is :2419200

here c# code for send message

public string SendMessage(string deviceId, string message)
{
string GoogleAppID = "XXXX";
var SENDER_ID = "XXXX";
var value = message;
WebRequest tRequest;
tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
tRequest.Method = "post";
tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key={0}", GoogleAppID));

        tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));

        string postData = "collapse_key="+collapseTb.Text+"&time_to_live=2419200&delay_while_idle=true&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + deviceId + "";

        Console.WriteLine(postData);
        Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        tRequest.ContentLength = byteArray.Length;

        Stream dataStream = tRequest.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();

        WebResponse tResponse = tRequest.GetResponse();

        dataStream = tResponse.GetResponseStream();

        StreamReader tReader = new StreamReader(dataStream);

        String sResponseFromServer = tReader.ReadToEnd();

        tReader.Close();
        dataStream.Close();
        tResponse.Close();
        return sResponseFromServer;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions