C2DM cannot receive messages from app server

Put your problem here if it does not fit any of the other categories.

C2DM cannot receive messages from app server

Postby vpachawa » Wed Nov 09, 2011 6:46 pm

Hi

My app has registered with Google C2DM and got the registration ID, and device Id.
Am sending the same to my app server.
My app server tries to push notification to the registration id.
App server gets 200 response code.
But I never get the notification from google.
During registration I gave my package name as "com.info.customer"
This is the same as in my manifest.
I have registered C2DMMessageReceiver in my manifest as well.

Here is my xml.
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.    package="com.info.customer"
  4.    android:versionCode="1"
  5.    android:versionName="1.0" >
  6.  
  7.     <uses-sdk android:minSdkVersion="8" />
  8.  
  9.     <permission
  10.        android:name="com.info.customer.permission.C2D_MESSAGE"
  11.        android:protectionLevel="signature" />
  12.     <!-- Permissions -->
  13.     <uses-permission android:name="com.info.customer.permission.C2D_MESSAGE" />
  14.     <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
  15.     <uses-permission android:name="android.permission.INTERNET" />
  16.     <uses-permission android:name="android.permission.WAKE_LOCK" />
  17.     <uses-permission android:name="android.permission.ACCOUNT_MANAGER" />
  18.     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  19.  
  20.     <application
  21.        android:icon="@drawable/ic_launcher"
  22.        android:label="@string/app_name" >
  23.  
  24.         <!-- Main activity. This activity is Launched when the app is loaded. -->
  25.          <activity
  26.            android:label="@string/app_name"
  27.            android:name="com.info.customer.ui.SplashScreenActivity" >
  28.             <intent-filter >
  29.                 <action android:name="android.intent.action.MAIN" />
  30.  
  31.                 <category android:name="android.intent.category.LAUNCHER" />
  32.             </intent-filter>
  33.         </activity>
  34.  
  35.         <!--
  36.             Only C2DM servers can send messages for the app. If permission is
  37.                         not set - any other app can generate it
  38.  
  39.        -->
  40.         <receiver
  41.            android:name=".c2dm.C2DMRegistrationReceiver"
  42.            android:permission="com.google.android.c2dm.permission.SEND" >
  43.             <intent-filter >
  44.                 <action android:name="com.google.android.c2dm.intent.REGISTRATION" >
  45.                 </action>
  46.  
  47.                 <category android:name="com.info.customer" />
  48.             </intent-filter>
  49.         </receiver>
  50.         <receiver
  51.            android:name=".c2dm.C2DMMessageReceiver"
  52.            android:permission="com.google.android.c2dm.permission.SEND" >
  53.             <intent-filter >
  54.                 <action android:name="com.google.android.c2dm.intent.RECEIVE" >
  55.                 </action>
  56.  
  57.                 <category android:name="com.info.customer" />
  58.             </intent-filter>
  59.         </receiver>
  60.  
  61.         <activity
  62.            android:configChanges="keyboardHidden|orientation"
  63.            android:label="@string/app_name"
  64.            android:name="com.info.customer.ui.VLocityCustomerActivity"
  65.            android:screenOrientation="portrait"
  66.            android:windowSoftInputMode="adjustPan" >
  67.         </activity>
  68.         <activity
  69.            android:configChanges="keyboardHidden|orientation"
  70.            android:label="@string/app_name"
  71.            android:name="com.info.customer.ui.MessageReceivedActivity"
  72.            android:screenOrientation="portrait"
  73.            android:windowSoftInputMode="adjustPan" >
  74.         </activity>
  75.     </application>
  76.  
  77. </manifest>
  78.  
Parsed in 0.009 seconds, using GeSHi 1.0.8.4


and my C2DMMessageReceiver class
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class C2DMMessageReceiver extends BroadcastReceiver {
  2.  
  3.         @Override
  4.         public void onReceive(Context context, Intent intent) {
  5.                 String action = intent.getAction();
  6.                 Log.w("C2DM", "Message Receiver called");
  7.                 if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
  8.                         Log.w("C2DM", "Received message");
  9.                         final String payload = intent.getStringExtra("payload");
  10.                         Log.d("C2DM", "dmControl: payload = " + payload);
  11.                         // TODO Send this to my application server to get the real data
  12.                         // Lets make something visible to show that we received the message
  13.                         createNotification(context, payload);
  14.  
  15.                 }
  16.         }
  17.  
  18.         public void createNotification(Context context, String payload) {
  19.                
  20.                 Log.i("MESSAGE RECEIVED ACTIVITY", "PAYLOAD = "+payload);
  21.                
  22.                 NotificationManager notificationManager = (NotificationManager) context
  23.                                 .getSystemService(Context.NOTIFICATION_SERVICE);
  24.                 Notification notification = new Notification(R.drawable.ic_launcher,
  25.                                 "Message received", System.currentTimeMillis());
  26.                 // Hide the notification after its selected
  27.                 notification.flags |= Notification.FLAG_AUTO_CANCEL;
  28.  
  29.                 Intent intent = new Intent(context, MessageReceivedActivity.class);
  30.                 intent.putExtra("payload", payload);
  31.                 PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
  32.                                 intent, 0);
  33.                 notification.setLatestEventInfo(context, "Message",
  34.                                 "New message received", pendingIntent);
  35.                 notificationManager.notify(0, notification);
  36.         }
  37. }
  38.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


notification never reaches my device. Log doesn't output any thing from C2DMMessageReciever class.
Is there any thing that I have done wrong here?
Any suggestions are extremely appreciated.

Thanks.
Regards,
Venkata Pachawa
vpachawa
Developer
Developer
 
Posts: 47
Joined: Tue Jun 08, 2010 8:54 pm
Location: St Catharines, Ontario, Canada

Top

Re: C2DM cannot receive messages from app server

Postby vpachawa » Wed Nov 09, 2011 10:34 pm

Fixed it. Now notifications are working. The problem was that I was using device email id for registration and sending that registration id to my app server.

I have to use the same email id for registering client (android) application and server application.
Regards,
Venkata Pachawa
vpachawa
Developer
Developer
 
Posts: 47
Joined: Tue Jun 08, 2010 8:54 pm
Location: St Catharines, Ontario, Canada

Re: C2DM cannot receive messages from app server

Postby tuffyg » Wed Mar 21, 2012 12:59 pm

hi.
could you please send me your message received activity? i am having a problem where by when i launch my application the first message is displayed and all other messages are not displayed. in my logcat the other messages (ones not showing) show as received and in my notification i print my payload so i know it works. its just not posting to my layout. it only shows the first message every time.
thanks in advance
tuffyg
Freshman
Freshman
 
Posts: 3
Joined: Tue Mar 20, 2012 5:24 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 16 guests