Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:24:45+00:00 2026-06-14T19:24:45+00:00

I am implementing an Android App that sends a message to PHP server then

  • 0

I am implementing an Android App that sends a message to PHP server then the PHP server that generates a GCM Push Notification directs it to the relevant Registration Ids. The problem is that the Notification isn’t shown although the GCMIntentService class received the message as it is shown in the attached log cat

HERE is the Android code

public class GCMIntentService extends GCMBaseIntentService {

private static final String TAG = "===GCMIntentService===";
private static final String senderId = "*****";
String message;

public GCMIntentService() {
    super(senderId);
}

static void displayMessage(Context context, String message) {
    Intent intent = new Intent("guc.edu.iremote.DISPLAY_MESSAGE");
    intent.putExtra("message", message);
    context.sendBroadcast(intent);
}

@Override
protected void onRegistered(Context arg0, String registrationId) {
    Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
    // sets the app name in the intent
    registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
    registrationIntent.putExtra("sender", senderId);
    startService(registrationIntent);
    Log.i(TAG, "Device registered: regId = " + registrationId);
    displayMessage(getApplicationContext(), "Your device registred with GCM");

}


@Override
protected void onUnregistered(Context arg0, String arg1) {
    Intent unregIntent = new Intent("com.google.android.c2dm.intent.UNREGISTER");
    unregIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
    startService(unregIntent);
    Log.i(TAG, "unregistered = " + arg1);
     displayMessage(getApplicationContext(), "Unregistered");

}

@Override
protected void onMessage(Context context, Intent intent) {
    message = intent.getStringExtra( "message" );
     // message = intent.getExtras().getString("message");

  Intent notificationIntent=new     Intent(context,this.getApplicationContext().getClass());
  PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
  WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |     PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
  wl.acquire();
  displayMessage(context, message);
 generateNotification(context, message, notificationIntent);

final AlertDialog.Builder d = new AlertDialog.Builder(context);
//Use an activity object here
 d.setMessage(message) //Provide a message here... A string or a string ID will do
 .setCancelable(false) //If you want them to be able to dismiss with a Back button
 .setPositiveButton(R.drawable.navigationaccept, new DialogInterface.OnClickListener()     {
     AlertDialog dialog = d.create();
    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub
        dialog.dismiss();


    }
}) 

 .create()
 .show();


}



@SuppressWarnings("deprecation")
private static void generateNotification(Context context, String message, Intent notificationIntent) {
     int icon = R.drawable.ic_launcher;
     long when = System.currentTimeMillis();


     NotificationManager notificationManager = (NotificationManager)
             context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);

    notificationManager.notify(0, notification);

     String title = context.getString(R.string.app_name);
     // set intent so it does not start a new activity
     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
             Intent.FLAG_ACTIVITY_SINGLE_TOP);
     PendingIntent intent =PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
     notification.setLatestEventInfo(context, title, message, intent);
     notification.flags |= Notification.FLAG_AUTO_CANCEL;
     notificationManager.notify(0, notification);
    notification.defaults |= Notification.DEFAULT_SOUND;
   notification.defaults |= Notification.DEFAULT_VIBRATE;
  notification.ledARGB = 0xff00ff00;
 notification.ledOnMS = 300;
 notification.ledOffMS = 1000;
 notification.flags |= Notification.FLAG_SHOW_LIGHTS;
 }

@Override
protected void onError(Context arg0, String errorId) {
    Log.i(TAG, "Received error: " + errorId);
     displayMessage(arg0, getString(R.string.gcm_error, errorId));
}

@Override
protected boolean onRecoverableError(Context context, String errorId) {
     displayMessage(context, getString(R.string.gcm_recoverable_error,
                errorId));
    return super.onRecoverableError(context, errorId);

}
}

AND here is the LOG CAT

11-22 22:49:10.747: V/GCMBroadcastReceiver(6305): onReceive: com.google.android.c2dm.intent.REGISTRATION
11-22 22:49:10.747: V/GCMBroadcastReceiver(6305): GCM IntentService class:     guc.edu.iremote.GCMIntentService
11-22 22:49:10.747: V/GCMBaseIntentService(6305): Acquiring wakelock

11-22 22:49:10.838: V/GCMBaseIntentService(6305): Intent service name:       GCMIntentService-55975***5670-181

11-22 22:49:10.877: D/GCMBaseIntentService(6305): handleRegistration: registrationId = ****, error = null, unregistered = null
11-22 22:49:10.877: D/GCMRegistrar(6305): resetting backoff for guc.edu.iremote
11-22 22:49:10.907: V/GCMRegistrar(6305): Saving regId on app version 1
11-22 22:49:10.927: I/===GCMIntentService===(6305): Device registered: regId = ****
11-22 22:49:10.957: V/GCMBaseIntentService(6305): Releasing wakelock

11-22 22:49:13.087: V/GCMBroadcastReceiver(6305): onReceive: com.google.android.c2dm.intent.REGISTRATION
11-22 22:49:13.087: V/GCMBroadcastReceiver(6305): GCM IntentService class: guc.edu.iremote.GCMIntentService
11-22 22:49:13.087: V/GCMBaseIntentService(6305): Acquiring wakelock

11-22 22:49:13.388: V/GCMBaseIntentService(6305): Intent service name: GCMIntentService-559753615670-182
11-22 22:49:13.388: I/Choreographer(6305): Skipped 67 frames!  The application may be doing too much work on its main thread.
11-22 22:49:13.417: D/GCMBaseIntentService(6305): handleRegistration: registrationId = ****, error = null, unregistered = null
11-22 22:49:13.430: D/GCMRegistrar(6305): resetting backoff for guc.edu.iremote
11-22 22:49:13.430: V/GCMRegistrar(6305): Saving regId on app version 1

11-22 22:49:13.477: I/===GCMIntentService===(6305): Device registered: regId = ****
11-22 22:49:13.477: V/GCMBaseIntentService(6305): Releasing wakelock
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:24:46+00:00Added an answer on June 14, 2026 at 7:24 pm

    try this code …

     package com.gcm.demo;
    
        import static com.gcm.demo.CommonUtilities.SENDER_ID;
        import static com.gcm.demo.CommonUtilities.displayMessage;
    
        import android.app.IntentService;
        import android.app.Notification;
        import android.app.NotificationManager;
        import android.app.PendingIntent;
        import android.content.Context;
        import android.content.Intent;
        import android.util.Log;
    
        import com.google.android.gcm.GCMBaseIntentService;
        import com.google.android.gcm.GCMRegistrar;
    
    
        /**
         * {@link IntentService} responsible for handling GCM messages.
         */
        public class GCMIntentService extends GCMBaseIntentService {
    
            @SuppressWarnings("hiding")
            private static final String TAG = "GCMIntentService";
    
            public GCMIntentService() {
                super(SENDER_ID);
                Log.i(TAG, "================Inside GCMIntentService Constructor==============================");
            }
    
            @Override
            protected void onRegistered(Context context, String registrationId) {
                Log.i(TAG, "================Inside onRegistered Method==============================");
                Log.i(TAG, "Device registered: regId = " + registrationId);
                displayMessage(context, getString(R.string.gcm_registered));
                ServerUtilities.register(context, registrationId);
            }
    
            @Override
            protected void onUnregistered(Context context, String registrationId) {
                Log.i(TAG, "================Inside onUnRegistered Method==============================");
                displayMessage(context, getString(R.string.gcm_unregistered));
                if (GCMRegistrar.isRegisteredOnServer(context)) {
                    ServerUtilities.unregister(context, registrationId);
                } else {
                    // This callback results from the call to unregister made on
                    // ServerUtilities when the registration to the server failed.
                    Log.i(TAG, "Ignoring unregister callback");
                }
            }
    
            @Override
            protected void onMessage(Context context, Intent intent) {
                Log.i(TAG, "================Inside OnMessage Method==============================");
                Log.i(TAG, "Received message");
                String message = getString(R.string.gcm_message);
                displayMessage(context, message);
                // notifies user
                generateNotification(context, message);
            }
    
            @Override
            protected void onDeletedMessages(Context context, int total) {
                Log.i(TAG, "================Inside onDeletedMessages Method==============================");
                Log.i(TAG, "Received deleted messages notification");
                String message = getString(R.string.gcm_deleted, total);
                displayMessage(context, message);
                // notifies user
                generateNotification(context, message);
            }
    
            @Override
            public void onError(Context context, String errorId) {
                Log.i(TAG, "================Inside onError Method==============================");
                Log.i(TAG, "Received error: " + errorId);
                displayMessage(context, getString(R.string.gcm_error, errorId));
            }
    
            @Override
            protected boolean onRecoverableError(Context context, String errorId) {
                // log message
                Log.i(TAG, "================Inside onRecoverableError Method==============================");
                Log.i(TAG, "Received recoverable error: " + errorId);
                displayMessage(context, getString(R.string.gcm_recoverable_error,
                        errorId));
                return super.onRecoverableError(context, errorId);
            }
    
            /**
             * Issues a notification to inform the user that server has sent a message.
             */
            private static void generateNotification(Context context, String message) {
                Log.i(TAG, "================Inside generateNotification Method==============================");
                int icon = R.drawable.ic_stat_gcm;
                long when = System.currentTimeMillis();
                NotificationManager notificationManager = (NotificationManager)
                        context.getSystemService(Context.NOTIFICATION_SERVICE);
                Notification notification = new Notification(icon, message, when);
                String title = context.getString(R.string.app_name);
                Intent notificationIntent = new Intent(context, DemoActivity.class);
                // set intent so it does not start a new activity
                notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                        Intent.FLAG_ACTIVITY_SINGLE_TOP);
                PendingIntent intent =
                        PendingIntent.getActivity(context, 0, notificationIntent, 0);
                notification.setLatestEventInfo(context, title, message, intent);
                notification.flags |= Notification.FLAG_AUTO_CANCEL;
                notificationManager.notify(0, notification);
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing C2DM push into an Android-app, and have come to the part
What is the appropriate way to implement a location-based Android app that periodically sends
I was having problems earlier implementing in-app billing for android. I have fixed that
I am implementing C2DM (possibly not relevant) in an android app testing on an
I am implementing in app purchases for Android. And in documentation they write: registerObserver()
I'm working on an Android app that needs to be able to display information
I am implementing Localytics.com useage statistics in my Android app. I am still just
I'm implementing in-app billing support in my application. I just realized that even though
While implementing the in-app billing for Android application, I came across a problem. Let
I'm developing an iPhone (and later Android) app that has real-time features, i.e. when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.