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 8909485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:26:31+00:00 2026-06-15T03:26:31+00:00

I am new to Android. I am trying to send message (GCM) from my

  • 0

I am new to Android. I am trying to send message (GCM) from my server (Java) to android phone. On debugging the server code, I found that the messages are successfully sent to android phones. But I was not able to receive any messages in phone. I tried to have a break-point in onMessage(), but there was no use.

Once after the every message from server, my phone is only getting an alert box something like: “PROJECT is not responding. Would you like to close it?” It has 2 buttons in the alert box: wait and OK.

Can anyone please help me on this. Even though, my server sent messages successfully, Why I was not receiving any messages in phone. My client and server code are as follows:

Server:

public void sendPushNotification(String theRegistrationId, String thePushMsg)
    {
        //Used to transmit messages to the Google Cloud Messaging service.
        Sender aGcmSender = new Sender(API_KEY); 

        //Constructing message which need to be transmitted to android device.      
        Message aMessage = new Message.Builder().addData("message", thePushMsg).build(); 
        try 
        {
            Result result = aGcmSender.send(aMessage, theRegistrationId, 1); 
        }
        catch (Exception theException) 
        {

        }
    }

Client:
AndroidManifest.xml:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<permission android:name="com.test.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.test.app.permission.C2D_MESSAGE" />

<uses-permission android:name="android.permission.INTERNET" />

<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.READ_OWNER_DATA" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Permission to vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />

<uses-permission android:name="android.permission.SET_DEBUG_APP"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:name="MyApplication">
    <uses-library android:name="com.google.android.maps" />

    <activity
        android:name=".view.welcome.WelcomeView"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
      <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="com.test.app" />
      </intent-filter>
    </receiver>

    <service android:name="com.test.app.GCMIntentService" />

</application>

GCMIntentService:

package com.test.app;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.google.android.gcm.GCMBaseIntentService;

public class GCMIntentService extends GCMBaseIntentService
{
    private static final String TAG = "===GCMIntentService===";
    private static String GCM_SENDER_ID = "697532398835"; //Project id in Google API Console

    public GCMIntentService() 
    {
        super(GCM_SENDER_ID);
        Log.d(TAG, "GCMIntentService init");
    }

    @Override
    protected void onRegistered(Context theContext, String theRegistrationId) 
    {
        Log.i(TAG, "Device registered: regId = " + theRegistrationId);
    }

    @Override
    protected void onUnregistered(Context theContext, String theArg) 
    {
        Log.i(TAG, "unregistered = "+theArg);
    }

    @Override
    protected void onMessage(Context theContext, Intent theIntent) 
    {
        Log.i(TAG, "new message= ");

        String aMessage = theIntent.getStringExtra("message");
        sendGCMIntent(theContext, aMessage);
    }

    private void sendGCMIntent(Context theContext, String theMessage) 
    {
        Intent aBroadcastIntent = new Intent();
        aBroadcastIntent.setAction("GCM_RECEIVED_ACTION");
        aBroadcastIntent.putExtra("gcm", theMessage);
        theContext.sendBroadcast(aBroadcastIntent);
    }

    @Override
    protected void onError(Context theContext, String theErrorId) 
    {
        Log.i(TAG, "Received error: " + theErrorId);
    }

    @Override
    protected boolean onRecoverableError(Context theContext, String theErrorId) 
    {
        return super.onRecoverableError(theContext, theErrorId);
    }
}

My activity:

package com.test.app.view.welcome;

import java.net.MalformedURLException;
import java.net.URL;

import com.google.android.gcm.GCMRegistrar;

public class LoginView extends Activity implements Runnable {

    Typeface itsTypeFace;
    IntentFilter gcmFilter;
    String broadcastMessage = "No broadcast message";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.login);

        gcmFilter = new IntentFilter();
        gcmFilter.addAction("GCM_RECEIVED_ACTION");         

    }

    private BroadcastReceiver gcmReceiver = new BroadcastReceiver() 
    {
        @Override
        public void onReceive(Context context, Intent intent) 
        {
            broadcastMessage = intent.getExtras().getString("gcm");
            if (broadcastMessage != null) 
            {
                System.out.println(broadcastMessage);
            }
        }
    };

    /**
     * Method to avoid back key press for a higher api level 2.0 and above
     */
    @Override
    public void onBackPressed() {}

    /** If the user changes the orientation of his phone, the current activity
        is destroyed, and then re-created.  This means that our broadcast message
        will get wiped out during re-orientation.
        So, we save the broad cast message during an onSaveInstanceState()
        event, which is called prior to the destruction of the activity.
    */
    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) 
    {
        super.onSaveInstanceState(savedInstanceState);
        savedInstanceState.putString("BroadcastMessage", broadcastMessage);

    }

    /** When an activity is re-created, the os generates an onRestoreInstanceState()
        event, passing it a bundle that contains any values that you may have put
        in during onSaveInstanceState()
        We can use this mechanism to re-display our last broadcast message.
    */
    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) 
    {
        super.onRestoreInstanceState(savedInstanceState);
        broadcastMessage = savedInstanceState.getString("BroadcastMessage");
    }

    /** If our activity is paused, it is important to UN-register any
        broadcast receivers.
    */
    @Override
    protected void onPause() 
    {
        unregisterReceiver(gcmReceiver);
        super.onPause();
    }

    /** When an activity is resumed, be sure to register any
        broadcast receivers with the appropriate intent
    */
    @Override
    protected void onResume() 
    {
        super.onResume();
        registerReceiver(gcmReceiver, gcmFilter);
    }

    /** 
     * The call to GCMRegistrar.onDestroy()
     */
    @Override
    public void onDestroy() 
    {
        GCMRegistrar.onDestroy(this);
        super.onDestroy();
    }
}

Can anyone please help me on this issue. Even though, my server sent messages successfully, Why I was not receiving any messages in phone.

  • 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-15T03:26:33+00:00Added an answer on June 15, 2026 at 3:26 am

    I found a solution for this problem. On deploying my application (server side), I found there was some problem with json-simple.jar.

    I have upgraded the jar to json-simple-1.1.1.jar and it worked!

    And also as NickT suggested, I have updated my canonicalid as follows:

    Sender aGcmSender = new Sender(API_KEY);     
    //Constructing message which need to be transmitted to android device.      
    Message aMessage = new Message.Builder().addData("message", thePushMsg).build(); 
    
    Result result = aGcmSender.send(aMessage, REG_ID, 1); //Transmitting message to android device
    if(result != null)
    {
        if(result.getMessageId() != null)
        {
            String aCanonicalRegistrationId = result.getCanonicalRegistrationId();
            if(aCanonicalRegistrationId != null)
            {
                //Updated my database with aCanonicalRegistrationId (replaced REG_ID)
            }
        }
        else 
        {  
            String error = result.getErrorCodeName();
            if (error.equals(Constants.ERROR_NOT_REGISTERED)) {    
                // application has been removed from device - unregister database
            }
        }
       }
    }
    

    Thank You.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send the Direct messages from my Android app. For that
I'm trying to send a sqlite database from my android phone to a web
So i'm trying to send some data from my c# server to my gcm
what I'm trying to do is to send some JSON from an Android phone
I am trying to create an android app that communicates with a local server
I'm trying to send data from my Android app to my PC over TCP.
As many other newbies to java and android i'm trying to run gcm demo
I am new to Mono For Android and im trying to send one typed-text
I am trying to send a GET via Android's HttpURLConnection (imported from org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection ),
I want to send posts from Android to Facebook wall. Some initial code works

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.