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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:58:56+00:00 2026-06-14T14:58:56+00:00

I am new to android and doing a demo app for gcm push notification.

  • 0

I am new to android and doing a demo app for gcm push notification.

I have developed all this code and GCM push notification is coming on devices in my environment, but when I test this code in other network device gets registration id,but server side gets mismatch sender id response when sending messages to cloud.
My code is given bellow:

        checkNotNull(CommonUtilities.SENDER_ID, "SENDER_ID");

    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this);

    setContentView(R.layout.activity_push_android);
    mDisplay = (TextView) findViewById(R.id.display);

    final String regId = GCMRegistrar.getRegistrationId(this);
    Log.i(TAG, "registration id =====  " + regId);

    if (regId.equals("")) {
        GCMRegistrar.register(this, CommonUtilities.SENDER_ID);
    } else {
        // Device is already registered on GCM
        if (GCMRegistrar.isRegisteredOnServer(this)) {
            // Skips registration.
            Toast.makeText(getApplicationContext(),
                    "Already registered with GCM", Toast.LENGTH_LONG)
                    .show();
        } else {
            // Try to register again, but not in the UI thread.
            // It's also necessary to cancel the thread onDestroy(),
            // hence the use of AsyncTask instead of a raw thread.
            // final Context context = this;
            mRegisterTask = new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    // Register on our server
                    // On server creates a new user
                    // ServerUtilities.register(context, name, email,
                    // regId);
                    return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                    mRegisterTask = null;
                    mDisplay.setText("ffffff        " + regId);
                }

            };
            mRegisterTask.execute(null, null, null);
        }
    }
    // regId = GCMRegistrar.getRegistrationId(this);
    mDisplay.setText("ffffff        " + regId);
    Log.i(TAG, "registration id =====!!!!  " + regId);
}

private void checkNotNull(Object reference, String name) {
    if (reference == null) {
        throw new NullPointerException(getString(R.string.error_config,
                name));
    }
}

@Override
protected void onPause() {
    super.onPause();
    GCMRegistrar.unregister(this);
}
  }

receiver:

public GCMIntentService() {
    super(CommonUtilities.SENDER_ID);

}

private static final String TAG = "===GCMIntentService===";

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

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

@Override
protected void onMessage(Context arg0, Intent message) {
    Bundle extras = message.getExtras();

    for (String key : extras.keySet()) {
        Log.d(getClass().getSimpleName(),
                String.format("onMessage: %s=%s", key,
                        extras.getString(key)));

        Toast.makeText(getApplicationContext(), "hii", Toast.LENGTH_LONG)
                .show();
    }
    Log.i(TAG, "new message= ");

    // ///////////////////

    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.ic_launcher,
            (CharSequence) message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context,
            PushAndroidActivity.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, (CharSequence) message,
            intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

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

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

This code has given me a registration id successfully.To test my code I have executed a java class to send message to cloud.That java class is:

  public static void main(String args[]) {

    try {

        Sender sender = new Sender(
                "my server api");

        ArrayList<String> devicesList = new ArrayList<String>();

        devicesList
                .add("reg id");
        // devicesList.add("reg id");

        // Use this line to send message without payload data
        // Message message = new Message.Builder().build();

        // use this line to send message with payload data
        Message message = new Message.Builder()
                .collapseKey("1")
                .timeToLive(3)
                .delayWhileIdle(true)
                .addData("message",
                        "this text be will be seen in notification bar!!")
                .build();

        // Use this code to send to a single device
        // Result result = sender
        // .send(message,
        // "APA91bGiRaramjyohc2lKjAgFGpzBwtEmI8tJC30O89C2b3IjP1CuMeU1h9LMjKhmWuZwcXZjy1eqC4cE0tWBNt61Kx_SuMF6awzIt8WNq_4AfwflaVPHQ0wYHG_UX3snjp_U-5kJkmysdRlN6T8xChB1n3DtIq98w",
        // 1);

        // Use this for multicast messages
        MulticastResult result = sender.send(message, devicesList, 1);
        sender.send(message, devicesList, 1);

        System.out.println(result.toString() + "\n");
        if (result.getResults() != null) {
            int canonicalRegId = result.getCanonicalIds();
            if (canonicalRegId != 0) {
                System.out.println(canonicalRegId);
            }
        } else {
            int error = result.getFailure();
            System.out.println(error);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
  }

Now the problem is I am not getting any push notification or log cat message.Thanks in advance for help.
Manifest:

sdk
android:minSdkVersion=”8″
android:targetSdkVersion=”16″ />

<permission
    android:name="com.sagar.gcma.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.sagar.gcma.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".PushAndroidActivity"
        android:label="@string/title_activity_push_android" >
        <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.sagar.gcma" />
        </intent-filter>
    </receiver>

    <service android:name=".GCMIntentService" />
</application>
  • 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-14T14:58:57+00:00Added an answer on June 14, 2026 at 2:58 pm

    At last I found the reason.My company firewall was blocking all messages from GCM. So I just removed firewall and able to receive messages from GCM . Go through this link to know more about firewall issues

    Hope it will help somebody in future.

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

Sidebar

Related Questions

Doing Android development on a Mac and this very new phone I have doesn't
I am doing Android Development using Eclipse. I have downloaded all the required software,
I am new to android development, and I have an app that when run
i am creating a new android application.i am using the table layout. I have
I am a new android app developer and i want to use google map
I am new android app developer i want make app for tablets and phone
I'm trying to record audio this.recorder = new android.media.MediaRecorder(); this.recorder.setAudioSource(android.media.MediaRecorder.AudioSource.MIC); this.recorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.DEFAULT); this.recorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.DEFAULT); this.recorder.setOutputFile(pruebaAudioRecorder.mp4); **this.recorder.prepare();**
I'm doing Major Project on my final year and I'm very new to Android
I'm doing Major Project on my final year and I'm very new to Android
As many other newbies to java and android i'm trying to run gcm demo

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.