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

  • Home
  • SEARCH
  • 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 6573049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:04:59+00:00 2026-05-25T15:04:59+00:00

public void StartRegistrationNotification() { Intent registrationIntent = newIntent(com.google.android.c2dm.intent.REGISTER); registrationIntent.setPackage(com.google.android.gsf); registrationIntent.putExtra(app, PendingIntent.getBroadcast(this, 0, new Intent(),

  • 0
           public void StartRegistrationNotification()
        {
            Intent registrationIntent = newIntent("com.google.android.c2dm.intent.REGISTER");
            registrationIntent.setPackage("com.google.android.gsf");
             registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
            registrationIntent.putExtra("sender", "kanika.saya@gmail.com");
                   this.startService(registrationIntent);  
              Log.i("Recieve","1");
        }


            public class ReceiverC2DM extends android.content.BroadcastReceiver 

           {

     private static String KEY = "c2dmPref";
     private static String REGISTRATION_KEY = "registraionKey";
     private Context context;

    // wakelock
    private static final String WAKELOCK_KEY = "C2DM_FAX";
    private static PowerManager.WakeLock mWakeLock;

    @Override
    public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
        this.context = context;
          Toast.makeText(context,"At broadcast receiver", Toast.LENGTH_LONG).show();
        runIntentInService(context, intent);
        Toast.makeText(context,"runIntentInService", Toast.LENGTH_LONG).show();
        if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION")) {
            handleRegistration(context, intent);
        } else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE"))     {
            handleMessage(context, intent);
        }
     }

    private void handleRegistration(Context context, Intent intent) {
        String registration = intent.getStringExtra("registration_key");
        Log.e("registration :","registration :"+registration);
        Toast.makeText(context,"registration :"+registration,     Toast.LENGTH_LONG).show();
        if (intent.getStringExtra("error") != null) {
            // Registration failed, should try again later.
            Log.d("c2dm", "registration failed");
            String error = intent.getStringExtra("error");
            if(error == "SERVICE_NOT_AVAILABLE"){
                Toast.makeText(context,"Service not available",     Toast.LENGTH_LONG).show();
                Log.d("c2dm", "SERVICE_NOT_AVAILABLE");
            }
            else if(error == "ACCOUNT_MISSING"){
                Toast.makeText(context,"Account Missing", Toast.LENGTH_LONG).show();
                Log.d("c2dm", "ACCOUNT_MISSING");
            }else if(error == "AUTHENTICATION_FAILED"){
                Toast.makeText(context,"Authentication failed", Toast.LENGTH_LONG).show();
                Log.d("c2dm", "AUTHENTICATION_FAILED");
            }else if(error == "TOO_MANY_REGISTRATIONS"){
                Toast.makeText(context,"too many registration", Toast.LENGTH_LONG).show();
                Log.d("c2dm", "TOO_MANY_REGISTRATIONS");
            }else if(error == "INVALID_SENDER"){
                Toast.makeText(context,"invalid sender", Toast.LENGTH_LONG).show();
                 Log.d("c2dm", "INVALID_SENDER");
            }else if(error == "PHONE_REGISTRATION_ERROR"){

                Log.d("c2dm", "PHONE_REGISTRATION_ERROR");
            }
        } else if (intent.getStringExtra("unregistered") != null) {
            // unregistration done, new messages from the authorized sender will be rejected
            Log.d("c2dm", "unregistered");

        } else if (registration != null) {
            Log.d("c2dm", registration);
            Toast.makeText(context,"registration!=null="+registration, Toast.LENGTH_LONG).show();
            Editor editor =
                context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
            editor.putString(REGISTRATION_KEY, registration);
            Toast.makeText(context,"registration :"+registration, Toast.LENGTH_LONG).show();
              editor.commit();

           // Send the registration ID to the 3rd party site that is sending the messages.
           // This should be done in a separate thread.
            // When done, remember that all registration is done.
        }
    }
    private void handleMessage(Context context, Intent intent)
    {

     String message = intent.getExtras().getString("payload");
     String key = intent.getExtras().getString("collapse_key");
     /*Log.e("","accountName : " +accountName);
     Log.e("","message : " +message);    
          Intent startActivity = new Intent(); 
            startActivity.setClass(context, NotificationAlert.class); 
            startActivity.setAction(NotificationAlert.class.getName()); 
            startActivity.setFlags( 
                    Intent.FLAG_ACTIVITY_NEW_TASK 
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);      
            startActivity.putExtra("Title", "Hello");
            startActivity.putExtra("Message", message);
            context.startActivity(startActivity);   
*/
          //Do whatever you want with the message         
              }

    static void runIntentInService(Context context, Intent intent) {
        if (mWakeLock == null) {
                // This is called from BroadcastReceiver, there is no init.
                PowerManager pm = 
                        (PowerManager) context.getSystemService(Context.POWER_SERVICE);
                mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 
                                WAKELOCK_KEY);
        }
        mWakeLock.acquire();

    }



}

    Manifest file is:

      <?xml version="1.0" encoding="utf-8"?>
         <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.synapse.reference"
      android:installLocation="auto"
      android:versionCode="1"
      android:versionName="2.2">
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="11" />

    <permission android:name="com.synapse.reference.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
     <uses-permission android:name="com.synapse.reference.permission.C2D_MESSAGE" />
      <!-- This app has permission to register and receive message -->
      <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
      <!-- Send the registration id to the server -->

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

    <uses-permission android:name="android.permission.WAKE_LOCK" />
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />



      <application android:icon="@drawable/icon" android:label="@string/app_name">                                                   <uses-permission android:name="android.permission.INTERNET"></uses-permission>



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

        </activity>
        <activity android:name=".MainMenuScreen">
         <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            </activity>
            <activity android:name=".ServerSimulator"/>    
          <activity android:name=".Information"/>
          <activity android:name=".About"/>

          <receiver android:name=".ReceiverC2DM"
        android:permission="com.google.android.c2dm.permission.SEND">
        <!-- Receive the actual message -->
        <intent-filter>

            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.synapse.reference" />
        </intent-filter>
        <!-- Receive the registration id -->
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.synapse.reference" />
        </intent-filter>
       </receiver>

       </application>
          </manifest>
  • 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-05-25T15:04:59+00:00Added an answer on May 25, 2026 at 3:04 pm
    private void handleRegistration(Context context, Intent intent) {
        String registration = intent.getStringExtra("registration_key");
    

    should actually be

    String registration = intent.getStringExtra("registration_id");
    

    Let me know if that works.

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

Sidebar

Related Questions

public void LoadAveragePingTime() { try { PingReply pingReply = pingClass.Send(logon.chronic-domination.com); double AveragePing = (pingReply.RoundtripTime
public void onBackPressed() { Intent setIntent = new Intent(this,xxxxx.class); startActivity(setIntent); return; } I call
public void test() { List<int> list = new List<int>(); list.Add(1); list.Add(2); list.Add(3); for (int
public void MyTest() { bool eventFinished = false; myEventRaiser.OnEvent += delegate { doStuff(); eventFinished
public void CardToPile() { waste.push(reserve.pop); }
public void Save() { XmlSerializer Serializer = new XmlSerializer(typeof(DatabaseInformation)); /* A first chance exception
public void EatDinner(string appetizer, string mainCourse, string dessert) { try { // Code }
[TestMethod] public void Memory() { var wr = new WeakReference(aaabbb); Assert.IsTrue(wr.IsAlive); GC.Collect(); GC.Collect(); GC.Collect();
public class UploadHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { ... // Create
[TestInitialize()] public void MyTestInitialize() { XmlTextWriter writer = new XmlTextWriter(DataFile.xml, Encoding.UTF8); writer.Formatting = Formatting.Indented;

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.