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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:24:54+00:00 2026-06-06T02:24:54+00:00

I followed this tutorial http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html I wrote the manifest File giving all the permissions

  • 0

I followed this tutorial http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html
I wrote the manifest File giving all the permissions which are sufficient.
But I’m getting registration Id null..Please help
Here’s the code I wrote:

public class C2DMClientActivity extends Activity {
/** Called when the activity is first created. */
final static String AUTH="authentication";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}
public void register(View view){//Register Button onclick event
    Log.w("C2DM","startRegistrationProcess");
    Intent intent=new Intent("com.google.android.c2dm.intent.REGISTER");
    intent.putExtra("app",PendingIntent.getBroadcast(this, 0, new Intent(), 0));
    intent.putExtra("sender","shubhamjindal18@gmail.com");
    startService(intent);
}
public void showRegistrationId(View view){//Show button onclick event
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
    String string=prefs.getString(AUTH,"n/a");
    Toast.makeText(this,string,Toast.LENGTH_LONG).show();
    Log.d("C2DM RegId",string);
}
}
public class C2DMRegistrationReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context,Intent intent){
    String string=intent.getAction();
    Log.w("C2DM","Registration Receiver Called");
    if ("com.google.android.c2dm.intent.REGISTRATION".equals(string)){
        Log.w("C2DM", "Received registration ID");
        final String str=intent.getStringExtra("registation_id");
        final String error=intent.getStringExtra("error");
        Log.d("C2DM", "dmControl: registrationId = " + str
                + ", error = " + error);
        String deviceId = Secure.getString(context.getContentResolver(),
                Secure.ANDROID_ID);
        createNotification(context, str);
        sendRegistrationIdToServer(deviceId,str);

        saveRegistrationId(context,str);
    }
}
public void saveRegistrationId(Context context,String str){
    SharedPreferences   prefs=PreferenceManager.getDefaultSharedPreferences(context);
    Editor edit=prefs.edit();
    edit.putString(C2DMClientActivity.AUTH,str);
    edit.commit();
}
public void createNotification(Context context,String str){
    NotificationManager notim=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification noti=new Notification(R.drawable.ic_launcher,"Registation Successful",System.currentTimeMillis());
    noti.flags|=Notification.FLAG_AUTO_CANCEL;
    Intent intent=new Intent(context,RegistrationResultActivity.class);
    intent.putExtra("registration_id", str);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
            intent, 0);
    noti.setLatestEventInfo(context, "Registration",
            "Successfully registered", pendingIntent);
    notim.notify(0, noti);
}
public void sendRegistrationIdToServer(String deviceId,
        String registrationId) {
    Log.d("C2DM", "Sending registration ID to my application server");
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("");
    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        // Get the deviceID
        nameValuePairs.add(new BasicNameValuePair("deviceid", deviceId));
        nameValuePairs.add(new BasicNameValuePair("registrationid",
                registrationId));

        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = client.execute(post);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        String line = "";
        while ((line = rd.readLine()) != null) {
            Log.e("HttpResponse", line);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

public class RegistrationResultActivity extends Activity {
 @Override
    public void onCreate(Bundle savedInstanceState) {

        setContentView(R.layout.activity);
        Bundle extras=getIntent().getExtras();
        if (extras!=null){
            String str=extras.getString("registration_id");
            TextView tv=(TextView) findViewById(R.id.textView1);
            tv.setText(str);
        }
        super.onCreate(savedInstanceState);
    }
}
public class C2DMMessageReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context,Intent intent){
    String action=intent.getAction();
    Log.w("C2DM","Message Receiver called");
    if ("com.google.android.c2dm.intent.RECEIVE".equals(action)){
        Log.w("C2DM", "Received message");
        final String payload = intent.getStringExtra("payload");
        Log.d("C2DM", "dmControl: payload = " + payload);
        createNoti(context,payload);
    }
}
public void createNoti(Context context,String str){
    NotificationManager notim=(NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
    Notification noti=new Notification(R.drawable.ic_launcher,"Message received",System.currentTimeMillis());
    noti.flags|=Notification.FLAG_AUTO_CANCEL;
    Intent intent=new Intent(context,MessageResultActivity.class);
    intent.putExtra("payload",str);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
            intent, 0);
    noti.setLatestEventInfo(context, "Message",
            "New message received", pendingIntent);
    notim.notify(0, noti);
}
}
public class MessageResultActivity extends Activity{

 @Override
    public void onCreate(Bundle savedInstanceState) {

        setContentView(R.layout.activity);
        Bundle extras=getIntent().getExtras();
        if (extras!=null){
            String payload=extras.getString("payload");
            TextView tv=(TextView) findViewById(R.id.textView1);
            tv.setText(payload);
        }
        super.onCreate(savedInstanceState);
    }
}
  • 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-06T02:24:57+00:00Added an answer on June 6, 2026 at 2:24 am

    It should be registration_id but it is registation_id

     final String str=intent.getStringExtra("registation_id");
    

    should be

    final String str=intent.getStringExtra("registration_id ");
    

    https://developers.google.com/android/c2dm/#push

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

Sidebar

Related Questions

I followed this tutorial and got the basics of Content Providers : http://www.vogella.de/articles/AndroidSQLite/article.html But
I am a new facebook application deverloper. I followed this tutorial: http://www.adobe.com/devnet/facebook/articles/video_facebook_quick_start.html but I
I have followed this tutorial: http://www.phpjabbers.com/how-to-make-a-php-calendar-php26-6.html#comments to make a very basic calendar. My aim
I followed this tutorial http://www.ibm.com/developerworks/java/tutorials/j-jni/section2.html (C implementation) for implementing a simple example of JNI
I followed the simple tutorial @ http://www.devart.com/dotconnect/oracle/articles/Tutorial_EF.html (Which works perfectly, btw) combined with http://www.hanselman.com/blog/CreatingAnODataAPIForStackOverflowIncludingXMLAndJSONIn30Minutes.aspx
http://www.devx.com/wireless/Article/39101/0/page/2 I have followed this tutorial and got it to work and everything. now
I followed this tutorial http://www.tugberkugurlu.com/archive/api-key-authorization-through-query-string-in-asp-net-web-api-authorizationfilterattribute to create custom Authorization filter. I have CarController with
I followed this tutorial here: http://www.dannyherran.com/2011/02/facebook-php-sdk-and-codeigniter-for-basic-user-authentication/ It works great but when I enable CSRF
I followed along with this tutorial ( http://www.bit-101.com/blog/?p=1861 ) and noticed that upon saving
first time trying XNA Framework in C#.. followed this tutorial: http://www.uxmagic.com/blog/post/2010/08/17/e2809cHello-Worlde2809d-for-XNA-Game-Studio-40.aspx Everything's ok until

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.