Note that there are some explanatory texts on larger screens.

plurals
  1. POc2dm : how to receive the message in the device? (using PHP)
    text
    copied!<p>I have the registration id and auth token for c2dm. And then I pass store these values in db. and using php, i could send one message to c2dm server. But my problem is I dont know how to receive the message in the application. I am not sure whether my way of getting the message is correct or not. Anyway i will give it below.</p> <p>I have one activity which registers to the c2dm using registration intent. and one receiver to receive the reg_id and notification message. it is registering with c2dm and not to receive message. </p> <h2>manifest</h2> <p> </p> <pre><code> &lt;intent-filter&gt; &lt;action android:name="com.google.android.c2dm.intent.REGISTRATION"&gt;&lt;/action&gt; &lt;category android:name="my.android.c2dm"&gt;&lt;/category&gt; &lt;/intent-filter&gt; &lt;intent-filter&gt; &lt;action android:name="com.google.android.c2dm.intent.RECEIVE"&gt;&lt;/action&gt; &lt;category android:name="my.android.c2dm"&gt;&lt;/category&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; </code></pre> <h2>C2dmRegistration.class (activity)</h2> <pre><code> Intent objRegIntnet=new Intent("com.google.android.c2dm.intent.REGISTER"); objRegIntnet.putExtra("app",PendingIntent.getBroadcast(this,0,new Intent(),0)); objRegIntnet.putExtra("sender","mymail@gmail.com"); startService(objRegIntnet); </code></pre> <h2>c2dmReceiver</h2> <pre><code>public class c2dmReceiver extends BroadcastReceiver { private static String KEY = "c2dmPref"; private static String REGISTRATION_KEY = "registrationKey"; private Context context; @Override public void onReceive(Context context, Intent intent) { this.context = context; if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION")) { handleRegistration(context, intent); } else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) { handleMessage(context, intent); } } private void handleRegistration(Context context, Intent intent) { //handles registeration } private void handleMessage(Context context, Intent intent) { String title= intent.getStringExtra("title"); String message= intent.getStringExtra("msg"); Toast.makeText(context,"title : "+title+"\n message : "+message,1).show(); //Do whatever you want with the message } </code></pre> <p>please tell what is the mistake i have done...</p> <h2>UPDATE</h2> <p>Hi all, the same code is woring for me today. The mistake i have done is with php code. instaed of passing the values as POST, i sent it was as GET. When I changed it to POST, the toast message is showing. but yet some problems are there. </p> <p>The title, and msg values are null here. my php code is :</p> <pre><code>function sendMessageToPhone($authCode, $deviceRegistrationId, $msgType, $messageText) { //$messageText="have a nice day"; //$msgtype="important"; $headers = array('Authorization: GoogleLogin auth=' . $authCode); $data = array( 'registration_id' =&gt; $deviceRegistrationId, 'collapse_key' =&gt; $msgType, 'data.message' =&gt; $messageText ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://android.apis.google.com/c2dm/send"); if ($headers) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $response = curl_exec($ch); curl_close($ch); return $response; } </code></pre> <p>Actually i am not sure what type of values should use for collapse_key, and data.message variables. </p> <p>Please help me... Thank you...</p>
 

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