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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:23:52+00:00 2026-06-06T23:23:52+00:00

I am trying to retrieve gcm notification in my android mobile.Everything runs fine,my android

  • 0

I am trying to retrieve gcm notification in my android mobile.Everything runs fine,my android device gets the registrationid from the gcm server I send it to my PHP server save it.Then I run my PHP script with that registrationID to send notification on my android mobile.The notification doesn’t show up and my device shows a runtime exception(this exception doesn’t popup when I run it on my emulator).There is something wrong in my IntentService class which I am not able to understand from my logcat.

Here’s my IntentService Class:

package com.pack.gcm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager; 
import android.util.Log;

import android.widget.Toast;

public class MyIntentService extends IntentService {

public MyIntentService() {
    super("MuazzamService");
}

private static PowerManager.WakeLock sWakeLock;
    private static final Object LOCK = MyIntentService.class;



@Override
protected void onHandleIntent(Intent intent) {

     try {
            String action = intent.getAction();
            if (action.equals("com.google.android.c2dm.intent.REGISTRATION")) {
                handleRegistration(intent);
            } else if (action.equals("com.google.android.c2dm.intent.RECEIVE")) {
                handleMessage(intent);
            }
        } finally {
            synchronized(LOCK) {
                sWakeLock.release();
            }
        }
}

private void handleRegistration(Intent intent) {
      try {
        String registrationId = intent.getStringExtra("registration_id");
        String error = intent.getStringExtra("error");
        String unregistered = intent.getStringExtra("unregistered");       
        // registration succeeded
        if (registrationId != null) {

            this.SendRegistrationIDViaHttp(registrationId);
            Log.i("Regid",registrationId);
        }

        if (unregistered != null) {
        } 

        if (error != null) {
            if ("SERVICE_NOT_AVAILABLE".equals(error)) {
               Log.e("ServiceNoAvail",error);

            } 
            else {
                Log.i("Error In Recieveing regid", "Received error: " + error);
            }
        }
      }catch(Exception e)
      {
          Log.e("ErrorHai(MIS0)",e.toString());
          e.printStackTrace();
      }
}

private void SendRegistrationIDViaHttp(String regID) {

    HttpClient httpclient = new DefaultHttpClient();
 try
 {
    Context context = getApplicationContext();

    HttpGet httpget = new   
            HttpGet("http://192.168.1.12/php/GCM/AndroidRequest.php?registrationID="+regID+"&email=muazzamalii@hotmail.com");   //test purposes k liye muazzam
    HttpResponse response = httpclient.execute(httpget);
    HttpEntity entity=response.getEntity();
    if(entity!=null)
    {
          InputStream inputStream=entity.getContent();
          String result= convertStreamToString(inputStream);
          Log.i("finalAnswer",result);
          Toast tst=Toast.makeText(context,regID, Toast.LENGTH_SHORT);
          tst.show();
    }
}
catch (ClientProtocolException e) 
{
    Log.e("errorhai",e.getMessage());
    e.printStackTrace();
}
catch (IOException e) 
{
    Log.e("errorhai",e.getMessage());
    e.printStackTrace();
}
}
    private static String convertStreamToString(InputStream is) {

    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } catch (IOException e) {
        Log.e("ErrorHai(MIS)",e.toString());
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            Log.e("ErrorHai(MIS2)",e.toString());
            e.printStackTrace();
        }
    }
    return sb.toString();
}

private void handleMessage(Intent intent) {
    String score = intent.getStringExtra("score");
    String time = intent.getStringExtra("time");

    Log.i("GetExtraScore",score);
    Log.i("GetExtratime",time);
}

static void runIntentInService(Context context,Intent intent){
     synchronized(LOCK) {

         if (sWakeLock == null) {
                PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
                sWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "my_wakelock");
            }
        }
        sWakeLock.acquire();
        intent.setClassName(context, MyIntentService.class.getName());
        context.startService(intent);
}

}

Here’s my Logcat:

 07-04 23:00:41.979: E/AndroidRuntime(9987): FATAL EXCEPTION: IntentService[MuazzamService]
 07-04 23:00:41.979: E/AndroidRuntime(9987): java.lang.NullPointerException: println needs a message
 07-04 23:00:41.979: E/AndroidRuntime(9987):    at android.util.Log.println_native(Native Method)
 07-04 23:00:41.979: E/AndroidRuntime(9987):    at android.util.Log.i(Log.java:158)
 07-04 23:00:41.979: E/AndroidRuntime(9987):    at com.pack.gcm.MyIntentService.handleMessage(MyIntentService.java:139)
 07-04 23:00:41.979: E/AndroidRuntime(9987):    at com.pack.gcm.MyIntentService.onHandleIntent(MyIntentService.java:41)
 07-04 23:00:41.979: E/AndroidRuntime(9987):    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
 07-04 23:00:41.979: E/AndroidRuntime(9987):    at android.os.Handler.dispatchMessage(Handler.java:99)
 07-04 23:00:41.979: E/AndroidRuntime(9987):    at android.os.Looper.loop(Looper.java:123)
 07-04 23:00:41.979: E/AndroidRuntime(9987):    at android.os.HandlerThread.run(HandlerThread.java:60)
 07-04 23:01:48.089: E/AndroidRuntime(10099): FATAL EXCEPTION: IntentService[MuazzamService]
 07-04 23:01:48.089: E/AndroidRuntime(10099): java.lang.NullPointerException: println needs a message
 07-04 23:01:48.089: E/AndroidRuntime(10099):   at android.util.Log.println_native(Native Method)
 07-04 23:01:48.089: E/AndroidRuntime(10099):   at android.util.Log.i(Log.java:158)
 07-04 23:01:48.089: E/AndroidRuntime(10099):   at com.pack.gcm.MyIntentService.handleMessage(MyIntentService.java:139)    
 07-04 23:01:48.089: E/AndroidRuntime(10099):   at com.pack.gcm.MyIntentService.onHandleIntent(MyIntentService.java:41)
 07-04 23:01:48.089: E/AndroidRuntime(10099):   at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
 07-04 23:01:48.089: E/AndroidRuntime(10099):   at android.os.Handler.dispatchMessage(Handler.java:99)
 07-04 23:01:48.089: E/AndroidRuntime(10099):   at android.os.Looper.loop(Looper.java:123)
 07-04 23:01:48.089: E/AndroidRuntime(10099):   at android.os.HandlerThread.run(HandlerThread.java:60)
 07-04 23:11:36.189: E/AndroidRuntime(10310): FATAL EXCEPTION: IntentService[MuazzamService]
 07-04 23:11:36.189: E/AndroidRuntime(10310): java.lang.NullPointerException: println needs a message
 07-04 23:11:36.189: E/AndroidRuntime(10310):   at android.util.Log.println_native(Native Method)
 07-04 23:11:36.189: E/AndroidRuntime(10310):   at android.util.Log.i(Log.java:158)
 07-04 23:11:36.189: E/AndroidRuntime(10310):   at com.pack.gcm.MyIntentService.handleMessage(MyIntentService.java:139)
 07-04 23:11:36.189: E/AndroidRuntime(10310):   at com.pack.gcm.MyIntentService.onHandleIntent(MyIntentService.java:41)
 07-04 23:11:36.189: E/AndroidRuntime(10310):   at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
 07-04 23:11:36.189: E/AndroidRuntime(10310):   at android.os.Handler.dispatchMessage(Handler.java:99)
 07-04 23:11:36.189: E/AndroidRuntime(10310):   at android.os.Looper.loop(Looper.java:123)
 07-04 23:11:36.189: E/AndroidRuntime(10310):   at android.os.HandlerThread.run(HandlerThread.java:60)
 07-04 23:12:31.739: E/AndroidRuntime(10482): FATAL EXCEPTION: IntentService[MuazzamService]
 07-04 23:12:31.739: E/AndroidRuntime(10482): java.lang.NullPointerException: println needs a message
 07-04 23:12:31.739: E/AndroidRuntime(10482):   at android.util.Log.println_native(Native Method)
 07-04 23:12:31.739: E/AndroidRuntime(10482):   at android.util.Log.i(Log.java:158)
 07-04 23:12:31.739: E/AndroidRuntime(10482):   at com.pack.gcm.MyIntentService.handleMessage(MyIntentService.java:139)
 07-04 23:12:31.739: E/AndroidRuntime(10482):   at com.pack.gcm.MyIntentService.onHandleIntent(MyIntentService.java:41)
 07-04 23:12:31.739: E/AndroidRuntime(10482):   at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59) 
 07-04 23:12:31.739: E/AndroidRuntime(10482):   at android.os.Handler.dispatchMessage(Handler.java:99)
 07-04 23:12:31.739: E/AndroidRuntime(10482):   at android.os.Looper.loop(Looper.java:123)
 07-04 23:12:31.739: E/AndroidRuntime(10482):   at android.os.HandlerThread.run(HandlerThread.java:60)
 07-04 23:13:57.199: E/AndroidRuntime(10541): FATAL EXCEPTION: IntentService[MuazzamService]   
 07-04 23:13:57.199: E/AndroidRuntime(10541): java.lang.NullPointerException: println needs a message
 07-04 23:13:57.199: E/AndroidRuntime(10541):   at android.util.Log.println_native(Native Method)
 07-04 23:13:57.199: E/AndroidRuntime(10541):   at android.util.Log.i(Log.java:158)
 07-04 23:13:57.199: E/AndroidRuntime(10541):   at com.pack.gcm.MyIntentService.handleMessage(MyIntentService.java:139)
 07-04 23:13:57.199: E/AndroidRuntime(10541):   at com.pack.gcm.MyIntentService.onHandleIntent(MyIntentService.java:41)
 07-04 23:13:57.199: E/AndroidRuntime(10541):   at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
 07-04 23:13:57.199: E/AndroidRuntime(10541):   at android.os.Handler.dispatchMessage(Handler.java:99)
 07-04 23:13:57.199: E/AndroidRuntime(10541):   at android.os.Looper.loop(Looper.java:123)
 07-04 23:13:57.199: E/AndroidRuntime(10541):   at android.os.HandlerThread.run(HandlerThread.java:60)

Update:

This is what i send from my php script:

    $message = '{"data":{"message":"one","some":"free"},"registration_ids":["xxxx"]}';

and this is what i get in result.

   {"multicast_id":8230995787169744326,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1341431581592147%5d17b789f9fd7ecd"}]}8.2309957871697E+18
  • 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-06T23:23:53+00:00Added an answer on June 6, 2026 at 11:23 pm

    Is this the JSON payload that you push to your device?

    { "data": 
      {
        "score": "5x1",
        "time": "15:10"
      },
      "registration_ids": [xxxxxx]
    }
    

    The above payload is required for your client code to work.

    Put a Null pointer check after these calls:

    String score = intent.getStringExtra("score");
    String time = intent.getStringExtra("time");
    

    Most likely score and time are both null, and causing the Log.i to crash

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

Sidebar

Related Questions

I am trying to retrieve my GCM registration ID from my android emulator but
i am trying to retrieve the data from the server with Linq ,there are
I am trying retrieve data from a .php file on a server from within
I'm trying to retrieve a file from a server using SFTP (as opposed to
Here I am trying to retrieve the response from the server and display it,
I am trying retrieve user name from the code through graph api, the below
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
Hi I am trying to retrieve values from database. I have a row which
I am trying to retrieve a column from another related table, and display that
I'm trying to retrieve product information from magento by calling its web service 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.