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

The Archive Base Latest Questions

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

I implemented a PHP code to send a notification to multiple Registration IDs but

  • 0

I implemented a PHP code to send a notification to multiple Registration IDs but after searching alot, i didn’t find an implementation to GCMIntentService & GCMBroadcastReciever that can show me how to implement it on my code
Here is the PHP code

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

$fields = array(
        'registration_ids'  => $apiKey,
        //'data'              => array( "message" => $message ),
        'data'  =>$message ,
);

$headers = array(
        'Authorization: key=' . "AIzaSyBCzOGxXyvvo8-ZSzesOsTIYa-7Ua64_SM",
        'Content-Type: application/json'
);

// Open connection
$ch = curl_init();

// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );

curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );

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

// Close connection
curl_close($ch);

echo $result;
}

AND here is my Android class that i implemented

package guc.edu.iremote;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.google.android.gcm.GCMBaseIntentService;

public class GCMIntentService extends GCMBaseIntentService {

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

public GCMIntentService() {
    super(senderId);
}

@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);

}

@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);
}

@Override
protected void onMessage(Context context, Intent intent) {
    intent.getStringExtra( "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();
 generateNotification(context, message, notificationIntent);



}

@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);
}

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

SO can Anyone please help me with what’s wrong OR missing in my Android code?

  • 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-14T21:01:25+00:00Added an answer on June 14, 2026 at 9:01 pm

    You’ve got the regids and the API key the wrong way round in the PHP. It needs to be something like:

    $registrationIDs = array(); 
    /* fetch values */
     while ($stmt2->fetch()) {
       $regidOne =  $dev_i; // Filling the array with the regids
       $registrationIDs[] = $regidOne;
    }
     $stmt2->close();
     $fields = array(
               'registration_ids' => $registrationIDs,
                 'data' => array("message" => $message),
                 'delay_while_idle'=> false,
                 'collapse_key'=>"".$randomNum.""
                );
       $headers = array(
            'Authorization: key=' . $apiKey,
             'Content-Type: application/json'
             );
    
      // Open connection
       $ch = curl_init();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented the image upload code using jquery php in my php web
I've implemented more complex AJAX before with javascript and PHP, but for some reason
I need to send an image to a SOAP web service implemented in PHP.
I have an own Tree object implemented in PHP. Say we have a tree
I have a website that is implemented in php/mysql, and is hosted at hostmonster
Possible Duplicate: Will XPath 2.0 and/or XSLT 2.0 be implemented in PHP? I think
I have a web service, defined(WSDL) and implemented in PHP. This one is relatively
I have implemented the jquery scroll text in my php web site. See my
I downloaded a program implemented in Java (in this case, http://julian.togelius.com/mariocompetition2009/index.php ). I first
I am developing a php web site. Here I have implemented clean URL using

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.