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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:15:33+00:00 2026-06-13T10:15:33+00:00

I have some server side code with which I am trying to create a

  • 0

I have some server side code with which I am trying to create a push notification. And the result looks like this:

{"multicast_id":8714083978034301091,"success":1,"failure":0,"canonical_ids":0,"r‌​esults":[{"message_id":"0:1350807053347963%9aab4bd8f9fd7ecd"}]}

and here is the PHP code I used to send that push notification. By the way the push didn’t happen so I am trying to figure out why:

$url = 'https://android.googleapis.com/gcm/send';

$device_ids = array( $device_id );

$t_data = array();
$t_data['message'] = 'Someone commented on your business.';

$t_json = array( 'registration_ids' => $device_ids , 'data' => $t_data );

// Open connection
$ch = curl_init();

curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: key=my_key', 'Content-Type: application/json' ) );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $t_json ) );

curl_setopt($ch, CURLOPT_URL, $url);

// Execute post
$result = curl_exec($ch);    

if ($result === FALSE)
{   
   die('Curl failed: ' . curl_error($ch));
}

// Close connection
curl_close($ch);

Here is the part of the manifest which deals with Google cloud messaging:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.problemio"
    android:versionCode="82"
    android:versionName="2.2.82" >

    <supports-screens  android:largeScreens="true"   android:normalScreens="true"  android:smallScreens="true"/> 

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"/>
    <!-- <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="xx"/>  -->

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

    <!-- Required permission to use in-app billing. -->
    <uses-permission android:name="com.android.vending.BILLING" />



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


    <!-- 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" />
    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 







    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:theme="@style/CustomTheme" 
        android:name="MyApplication"
        android:debuggable="true"
                >

        <!--  For Google Cloud Messaging -->
        <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.problemio" />
          </intent-filter>
        </receiver>   

        <service android:name=".GCMIntentService" />
        <!--  End of Google Cloud Messaging -->

EDIT:

Here is my whole GCMIntentService class:

package com.problemio;

import static com.google.android.gcm.GCMConstants.ERROR_SERVICE_NOT_AVAILABLE;
import static com.google.android.gcm.GCMConstants.EXTRA_ERROR;
import static com.google.android.gcm.GCMConstants.EXTRA_REGISTRATION_ID;
import static com.google.android.gcm.GCMConstants.EXTRA_SPECIAL_MESSAGE;
import static com.google.android.gcm.GCMConstants.EXTRA_TOTAL_DELETED;
import static com.google.android.gcm.GCMConstants.EXTRA_UNREGISTERED;
import static com.google.android.gcm.GCMConstants.INTENT_FROM_GCM_LIBRARY_RETRY;
import static com.google.android.gcm.GCMConstants.INTENT_FROM_GCM_MESSAGE;
import static com.google.android.gcm.GCMConstants.INTENT_FROM_GCM_REGISTRATION_CALLBACK;
import static com.google.android.gcm.GCMConstants.VALUE_DELETED_MESSAGES;

import java.util.Random;
import java.util.concurrent.TimeUnit;

import com.google.android.gcm.GCMBaseIntentService;

import android.app.AlarmManager;
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.graphics.Color;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;

import utils.GCMConstants;

public class GCMIntentService extends GCMBaseIntentService 
{

public GCMIntentService() 
{
        super(ProblemioActivity.SENDER_ID);
}

@Override
  protected void onRegistered(Context ctxt, String regId) {
    Log.d(getClass().getSimpleName(), "onRegistered: " + regId);
    Toast.makeText(this, regId, Toast.LENGTH_LONG).show();
  }

  @Override
  protected void onUnregistered(Context ctxt, String regId) {
    Log.d(getClass().getSimpleName(), "onUnregistered: " + regId);
  }

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

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

  @Override
  protected void onError(Context ctxt, String errorMsg) {
    Log.d(getClass().getSimpleName(), "onError: " + errorMsg);
  }

  @Override
  protected boolean onRecoverableError(Context ctxt, String errorMsg) {
    Log.d(getClass().getSimpleName(), "onRecoverableError: " + errorMsg);

    return(true);
  } 

  private static void generateNotification(Context context, String message, String title ) 
  {
        int icon = R.drawable.ic_launcher;
        long when = System.currentTimeMillis(); // can change this to a future time if desired

        NotificationManager notificationManager = 
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(context, ProblemioActivity.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);        
        Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);            

         Notification notification = new NotificationCompat.Builder(context)
         .setContentTitle(title)
         .setContentText(message)
         .setContentIntent(intent)
         .setSmallIcon(icon)
         .setLights(Color.YELLOW, 1, 2)
         .setAutoCancel(true)
         .setSound(defaultSound)
         .build();

        notificationManager.notify(0, notification);
}     

}

But not matter what I try the push notification does not appear on the physical device. Any ideas why not and how I can make it appear on the device?

  • 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-13T10:15:34+00:00Added an answer on June 13, 2026 at 10:15 am

    You only need to add to onMessage() the call to the notification function, like this:

    @Override
    protected void onMessage(Context ctxt, Intent message) {
        Bundle extras=message.getExtras();
    
        for (String key : extras.keySet()) {
          Log.d(getClass().getSimpleName(),
                String.format("onMessage: %s=%s", key,
                          extras.getString(key)));
        }
        generateNotification(ctxt, extras.getString("message"), "test title");
    

    }

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

Sidebar

Related Questions

I have an Ext TreePanel which I'm trying to add some server-side pagination to.
I have some troubles with receiving data on server side. Here goes the code:
I have some php files in a server which generate xml code in them.
I have a bunch of javascript functions which depend on some server-side constants (such
I have some code that uses the SQL Server 2005 SMO objects to backup
I have some data with a timestamp in SQL Server, I would like to
Developing server side code i finally got my eyes X-crossed trying to write -
I have some .NET remoting code where a factory method, implemented in some server
I have some client-server application. And as one of its part, I need to
I have some path c:\server\folderName1\another name\something\another folder\ . How i can extract from there

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.