Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Android Push Notification of the New GCM release using Coldfusion

Explorer ,
Aug 28, 2012 Aug 28, 2012

Is there any similar push notification solution/Tutorial but this time for the Android?

Something similar to this tutorial but with Android GCM using coldfusion to send from my dedicated server to the registered devices:

http://www.raymondcamden.com/index.cfm/2010/9/13/Guest-Post-Apple-Push -Notifications-From-ColdFusio...

Thanks in advance

Talal

2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Nov 21, 2012 Nov 21, 2012

well after diving and testing here and there I found a way and successfully tested.

1> First and formost, the developer need to follow the procedures in this page:

http://developer.android.com/guide/google/gcm/gs.html

2> In the app side, you will send users devices information; but all that matters is only the "registration id" , so make sure you save this in the database coz you'll use it to loop through your database records when sending notifications.

3> Now the server side script in Coldfusion

...
Translate
Explorer ,
Nov 21, 2012 Nov 21, 2012
LATEST

well after diving and testing here and there I found a way and successfully tested.

1> First and formost, the developer need to follow the procedures in this page:

http://developer.android.com/guide/google/gcm/gs.html

2> In the app side, you will send users devices information; but all that matters is only the "registration id" , so make sure you save this in the database coz you'll use it to loop through your database records when sending notifications.

3> Now the server side script in Coldfusion which is really easy:

<!---Place this above your html tag--->

<cfsetting requesttimeout="80000000000000">

<cfset appName = 'YourAppName'>

<cfset registrationArray = ArrayNew(1)>

<cfquery datasource="devicesDSN" name="rsCount">

    SELECT COUNT(intGCMuserID) AS TotalRecords

    FROM gcmusers_tbl

    WHERE appName = <cfqueryparam cfsqltype="cf_sql_clob" value="#appName#">

</cfquery>

<!---Google is limited to send only to 1000 devices at a time so we need to nest the cfloop of the array inside another cfloop pertaining to our total recordCount from the recordset so we'll use the Ceiling to control the number of loops needed to make sure we sent to all the users if they exceed google limit--->

<cfset LoopingNo = Ceiling(rsCount.TotalRecords/1000)>

<cfset fromRec = 1>

<cfset toRec = 1000>

<!---Now place the following code inside the body tag of your cfm page--->

<cfif isDefined("FORM.pushButton")>

    <cfquery datasource="devicesDSN" name="rs">

    SELECT regID

    FROM gcmusers_tbl

    WHERE appName = <cfqueryparam cfsqltype="cf_sql_clob" value="#appName#">

    ORDER BY intGCMuserID DESC

    </cfquery>

    <cfloop from="1" to="#loopingNo#" index="i">

        <cfloop query="rs">

            <cfset ArrayAppend(registrationArray, "#regID#")>

        </cfloop>

        <cfset stFields =

        { "data"= {

            "title" = "#FORM.title#",

            "message"= "#FORM.message#"

          },

          "registration_ids"= #registrationArray#

        }

        >

        <cfhttp url="https://android.googleapis.com/gcm/send" method="post" result="httpResp" timeout="600">

            <cfhttpparam type="header" name="Content-Type" value="application/json"/>

            <cfhttpparam type="header" name="Authorization" value="key=yourAPIkeyFromGoogle">

            <cfhttpparam type="body" value="#serializeJSON(stFields)#">

        </cfhttp>

        <cfset temp = ArrayClear(registrationArray)>

        <cfset fromRec = fromRec + 1000>

        <cfset toRec = toRec + 1000>

    </cfloop>

    <h2 align="center" style="color:red;">Sent to: <cfoutput>#rs.RecordCount#</cfoutput> Devices/Users </h2>

    <h3 align="center"><a href="thispage.cfm">&gt;&gt;&gt;again</a></h3>

<cfelse>

<cfform>

  <table width="400" border="1" align="center" cellpadding="2" cellspacing="2">

    <tr valign="top">

      <th scope="row">Title:</th>

      <td><label for="title"></label>

      <cfinput type="text" name="title" required="yes" id="title" maxlength="30" width="300" message="Type Title"></td>

    </tr>

    <tr valign="top">

      <th scope="row">Message:</th>

      <td><label for="message"></label>

      <cftextarea name="message" cols="45" rows="2" required="yes" id="message" maxlength="120" message="Type Message"></cftextarea></td>

    </tr>

    <tr>

      <th scope="row"> </th>

      <td><cfinput type="submit" name="pushButton" value="send" id="pushButton"></td>

    </tr>

  </table>

</cfform>

</cfif>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources