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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:14:46+00:00 2026-06-05T15:14:46+00:00

The code snippet: C2DMessaging.java public class C2DMessaging { public static final String EXTRA_SENDER =

  • 0

The code snippet:

C2DMessaging.java

public class C2DMessaging {
public static final String EXTRA_SENDER = "sender";
public static final String EXTRA_APPLICATION_PENDING_INTENT = "app";
public static final String REQUEST_UNREGISTRATION_INTENT = "com.google.android.c2dm.intent.UNREGISTER";
public static final String REQUEST_REGISTRATION_INTENT = "com.google.android.c2dm.intent.REGISTER";
public static final String LAST_REGISTRATION_CHANGE = "last_registration_change";
public static final String BACKOFF = "backoff";
public static final String GSF_PACKAGE = "com.google.android.gsf";
public static final String REGISTRATION_ID="registrationid";

// package
static final String PREFERENCE = "wea.com.google.android.c2dm";

private static final long DEFAULT_BACKOFF = 30000;

/**
 * Initiate c2d messaging registration for the current application
 */
public static void register(Context context,
        String senderId) {
    Intent registrationIntent = new Intent(REQUEST_REGISTRATION_INTENT);
    registrationIntent.setPackage(GSF_PACKAGE);
    registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT,
            PendingIntent.getBroadcast(context, 0, new Intent(), 0));
    registrationIntent.putExtra(EXTRA_SENDER, senderId);
    context.startService(registrationIntent);
    // TODO: if intent not found, notification on need to have GSF
}

/**
 * Unregister the application. New messages will be blocked by server.
 */
public static void unregister(Context context) {
    Intent regIntent = new Intent(REQUEST_UNREGISTRATION_INTENT);
    regIntent.setPackage(GSF_PACKAGE);
    regIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT, PendingIntent.getBroadcast(context,
            0, new Intent(), 0));
    context.startService(regIntent);
}

C2DMBroadcastReceiver.java

public class C2DMBroadcastReceiver extends BroadcastReceiver {

@Override
public final void onReceive(Context context, Intent intent) {
    // To keep things in one place.
    C2DMBaseReceiver.runIntentInService(context, intent);
    setResult(Activity.RESULT_OK, null /* data */, null /* extra */);        
}

}

Manifest file

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

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

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

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<!-- for push -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<permission
    android:name="com.buuuk.sgweatherlah.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.buuuk.sgweatherlah.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<application
    android:name=".MyApp"
    android:icon="@drawable/ic_launcher"
    android:installLocation="preferExternal"
    android:label="@string/app_name"
    android:theme="@style/full_screen" >
    <uses-library android:name="com.google.android.maps" />

    <activity
        android:name=".WeatherLahActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
        <!-- for push -->
        <service
            android:name=".C2DMReceiver"
            android:enabled="true" />

        <!--
      Only Google services can send messages to the app. If this permission
      weren't set any other app would be able to send messages to us.
        -->
        <receiver
            android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >

            <!-- Receive actual messages -->
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />

                <category android:name="com.buuuk.sgweatherlah" />
            </intent-filter>
            <!-- Receive registration ids -->
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="com.buuuk.sgweatherlah" />
            </intent-filter>
        </receiver>
    </service>
</application>

The problem is :

After i call

C2DMessaging.register(Context context,String senderId) 

method to register my app.

but i am not receiving anything in the C2DMBroadcastReceiver’s onReceive().

this is the structure image. i can’t post image here. So just upload to box.

https://www.box.com/s/22782990e6f0bc34bbeb

Pls help me. thanks

  • 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-05T15:14:47+00:00Added an answer on June 5, 2026 at 3:14 pm

    Problem in your manifest file

    you must write service and receiver tag within application tag

    for example:

    <application android:icon="@drawable/icon"
            android:label="@string/app_name">
    
    <service
                android:name=".C2DMReceiver"
                android:enabled="true" />
    
    <!--SAME FOR RECIEVER-->
    
    </application>
    

    One more thing..you are writing

    <receiver
                android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
    

    is your folder structure is com/google/android/c2dm/ which contains C2DMBroadcastReceiver class?

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

Sidebar

Related Questions

Relevant Code Snippet: public class MyPreference extends Preference { public MyPreference(Context context, AttributeSet attrs)
Code snippet used to allocate cache memory: private static Cache cache = CacheManager.getInstance().getCache(CACHE_NAME); public
I saw the following code snippet: class WindowHandle { public: WindowHandle(WINDOW_HANDLE handle) : w(handle)
In code snippet below, declaring the doThings() method as static would make the class
I frequently see a code snippet like this in class instance methods: static NSString
Code snippet.. if (regionalApprover == null) { throw new Exception(string.Format(The regional approver for {0}
This code snippet is from C# in Depth static bool AreReferencesEqual<T>(T first, T second)
Code snippet to follow. I have a struct (example code has class, tried both,
I found a good Code Snippet for Downloading Youtube Files with C# .net. http://sourcecodecenter.blogspot.com/2011/05/download-youtube-videos-with-c.html
I have this code snippet: String negativeBinary = ; negativeBinary = Integer.toBinaryString(decimal); System.out.println(negativeBinary); which

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.