Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A while back I had been playing around with C2DM to send push notifications. I altered my code as per changes mentioned on this page: <a href="http://developer.android.com/guide/google/gcm/c2dm.html#server" rel="nofollow">http://developer.android.com/guide/google/gcm/c2dm.html#server</a> to make use for GCM service:</p> <pre><code>Private Sub btnPush_Click(sender As Object, e As System.EventArgs) Handles btnPush.Click lblResponse.Text = SendNotification(AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA) End Sub </code></pre> <p>My SendNotification function:</p> <pre><code>Private Function SendNotification(ByVal authstring As String) As String ServicePointManager.ServerCertificateValidationCallback = Function(sender As Object, certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As SslPolicyErrors) True Dim request As WebRequest = WebRequest.Create("https://android.googleapis.com/gcm/send") request.Method = "POST" request.ContentType = "application/x-www-form-urlencoded" request.Headers.Add(String.Format("Authorization: key={0}", authstring)) Dim collaspeKey As String = Guid.NewGuid().ToString("n") Dim postData As String = String.Format("registration_id={0}&amp;data.payload={1}&amp;collapse_key={2}", deviceList.SelectedValue, txtPayload.Text, collaspeKey) Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData) request.ContentLength = byteArray.Length Dim dataStream As Stream = request.GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) dataStream.Close() Dim response As WebResponse = request.GetResponse() dataStream = response.GetResponseStream() Dim reader As New StreamReader(dataStream) Dim responseFromServer As String = reader.ReadToEnd() reader.Close() dataStream.Close() response.Close() Return responseFromServer End Function </code></pre> <p>It seems that GCM does not require you to authenticate against Google to obtain an auth key (as the case was with C2DM). Instead, you'll require an API key which is being passed to the SendNotification function. This page should help you get your API key set up: <a href="http://developer.android.com/guide/google/gcm/gs.html" rel="nofollow">http://developer.android.com/guide/google/gcm/gs.html</a></p> <p>The code for my web form is below just in case:</p> <pre><code>&lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:DropDownList ID="deviceList" runat="server"&gt; &lt;asp:ListItem Value="device-id-goes-here"&gt;Eclipse AVD&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="device-id-goes-here"&gt;My Phone 1&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="device-id-goes-here"&gt;My Phone 2&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;br /&gt;&lt;br /&gt; &lt;asp:TextBox ID="txtPayload" runat="server" Width="480px"&gt;&lt;/asp:TextBox&gt; &lt;br /&gt;&lt;br /&gt; &lt;asp:Button ID="btnPush" runat="server" Text="Push" /&gt; &lt;asp:Label ID="lblResponse" runat="server" Text=""&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>As for creating your Android app to receiving the push notifications, check out this link: <a href="http://developer.android.com/guide/google/gcm/gs.html#android-app" rel="nofollow">http://developer.android.com/guide/google/gcm/gs.html#android-app</a></p> <p>Don't forget to import System.Net, System.IO, System.Security.Cryptography.X509Certificates and System.Net.Security.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload