Created
May 6, 2011 12:52
-
-
Save anonymous/958901 to your computer and use it in GitHub Desktop.
after registering with C2DM i dont knw how to get registered id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Main.java | |
| Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER"); | |
| registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); | |
| registrationIntent.putExtra("sender", "tasolglobalsolution@gmail.com"); | |
| startService(registrationIntent); | |
| ------------------------ | |
| MyC2dmReceiver.java | |
| after this code i m writing this code:::> | |
| import android.app.Notification; | |
| import android.app.NotificationManager; | |
| import android.app.PendingIntent; | |
| import android.content.BroadcastReceiver; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.content.SharedPreferences.Editor; | |
| import android.util.Log; | |
| public class MyC2dmReceiver extends BroadcastReceiver { | |
| private static String KEY = "c2dmPref"; | |
| private static String REGISTRATION_KEY = "registrationKey"; | |
| private Context context; | |
| @Override | |
| public void onReceive(Context context, Intent intent) { | |
| this.context = context; | |
| Log.i("In Reciever Class","IN RECEIVER CLASS"); | |
| 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_id"); | |
| Log.d("Registration Id", registration); | |
| 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"){ | |
| Log.d("c2dm", "SERVICE_NOT_AVAILABLE"); | |
| }else if(error == "ACCOUNT_MISSING"){ | |
| Log.d("c2dm", "ACCOUNT_MISSING"); | |
| }else if(error == "AUTHENTICATION_FAILED"){ | |
| Log.d("c2dm", "AUTHENTICATION_FAILED"); | |
| }else if(error == "TOO_MANY_REGISTRATIONS"){ | |
| Log.d("c2dm", "TOO_MANY_REGISTRATIONS"); | |
| }else if(error == "INVALID_SENDER"){ | |
| 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 in Broadcast Receiver unregistered", "unregistered"); | |
| } else if (registration != null) { | |
| Log.d("c2dm in Broadcast Receiver Registered", registration); | |
| Editor editor = | |
| context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit(); | |
| editor.putString(REGISTRATION_KEY, registration); | |
| 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) | |
| { | |
| //Do whatever you want with the message | |
| Log.d("IN HANDLE MESSAGE", "You have been alert"); | |
| } | |
| } | |
| i m getting below error | |
| ERROR/C2DMRegistrar(1949): [C2DMReg] handleRequest caught javax.net.ssl.SSLException: SSL shutdown failed: ssl=0x27ee68: I/O error during system call, Broken pipe | |
| and if this error will not come so, how can i find wht is the registration id ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment