Search code examples
androidandroid-c2dm

C2DM hello world failing, getting 404 error on registration


I am trying to get basic functionality working to test with the Android C2DM service. I followed the example source found here:

http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html#c2dm

Here is the main activity which attempts the registration

public class C2DMClientActivity extends Activity {

public final static String AUTH = "authentication";

// Example Activity to trigger a request for a registration ID to the Google
// server
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

public void register(View view) {
    Log.w("C2DM", "start registration process");
    Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
    intent.putExtra("app",
            PendingIntent.getBroadcast(this, 0, new Intent(), 0));
    // Sender currently not used
    intent.putExtra("sender", "nonsense@gmail.com");
    startService(intent);
}

public void showRegistrationId(View view) {
    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);

}

}

Log cat result:

01-01 02:13:00.536: E/HttpResponse(670): <html><head>
01-01 02:13:00.536: E/HttpResponse(670): <meta http-equiv="content-type" content="text/html;charset=utf-8">
01-01 02:13:00.536: E/HttpResponse(670): <title>404 Not Found</title>
01-01 02:13:00.536: E/HttpResponse(670): </head>
01-01 02:13:00.536: E/HttpResponse(670): <body text=#000000 bgcolor=#ffffff>
01-01 02:13:00.536: E/HttpResponse(670): <h1>Error: Not Found</h1>
01-01 02:13:00.536: E/HttpResponse(670): <h2>The requested URL <code>/register</code> was not found on this server.</h2>
01-01 02:13:00.536: E/HttpResponse(670): <h2></h2>
01-01 02:13:00.536: E/HttpResponse(670): </body></html>

Is there any other information I can provide? Please let me know


Solution

  • The code you posted here has nothing to do with the error log you paste.

    Looking at the tutorial web, after successful registration on the device, it sends the info to your own server

    HttpPost post = new HttpPost("http://your_url/register");

    Looks like you forget to create the /register path