user517011
user517011

Reputation: 59

Get registration id by using c2dm on emulator

Hi~ I'm a beginner of android . And I try to get the registeration id by using the google's simple c2dm code... and here is my code...

Intent registrationIntent = new Intent ("com.google.android.c2dm.intent.REGISTER");
     registrationIntent.setPackage("com.imei"); //"com.imei"
   registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent   (), 0));
      registrationIntent.putExtra("sender", "[email protected]"); 
      Log.d("WelcomeScreen","[email protected]");

      TextView textview = (TextView)this.findViewById(R.id.textview);
      textview.setText("The Show Start...");

      Button mbutton = (Button)this.findViewById(R.id.button); //set a button to jump    
      mbutton.setOnClickListener(new View.OnClickListener()
{
  public void onClick(View v)
  { 
   System.out.println("adds");  //just for check
   startService(registrationIntent);
   Intent intent = new Intent(imei.this, showthinga.class);
   startActivity(intent);
   handleRegistration(getApplicationContext(), registrationIntent); 
   System.out.println("end");  //just for check
    }
  }); 
}

private void handleRegistration(Context context, Intent intent) 

{
String registration = intent.getStringExtra("registration_id");
if (intent.getStringExtra("error") != null) {
// Registration failed, should try again later. Log.e("ERROR", "ERROR");
} else if (intent.getStringExtra("unregistered") != null) {
// unregistration done, new messages from the authorized sender will be rejected Log.e("unregistered", "unregistered");
} else if (registration != null) {
// 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.
Log.e("registration", registration);
}
}
}

But everytime When I look at my logcat message... It always shows ... "Unable to start service intent {act=com.google.android.c2dm.intent.REGISTER pkg=com.imei(has extras):not find}" I've been refreshed my avd to "Google APIS by Google Inc,Android API8,revision 2"... But it still not working & that message alwaysed shown up ... so...Is there anything I missed or somthing I did wrong ?

Upvotes: 1

Views: 1558

Answers (1)

authorwjf
authorwjf

Reputation: 141

You need to create an emulator based on Google APIs (Google Inc.) level 8, rather than a specific version of the Android OS. You can do it from the Android SDK and AVD Manager in the eclipse plugin environment.

Upvotes: 1

Related Questions