0

Here is my code:

// begin the registration process
    status.setText("Registering...");
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("register.php");
    SharedPreferences settings = getSharedPreferences("settings", 0);
    String name = settings.getString("name", "");
    String email = settings.getString("email", "");
    String password = settings.getString("password", "");

    //get C2DM registration ID
    Context context = getApplicationContext();
    C2DMessaging.register(context, "qasim1iqbal");
    String reg_id = C2DMessaging.getRegistrationId(context);

    String HTML = "";
    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("name", name));
        nameValuePairs.add(new BasicNameValuePair("email", email));
        nameValuePairs.add(new BasicNameValuePair("password", password));
        nameValuePairs.add(new BasicNameValuePair("reg_id", reg_id));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);
        HTML = EntityUtils.toString(response.getEntity());
        Toast msg = Toast.makeText(getApplicationContext(), HTML, Toast.LENGTH_LONG);
        msg.show();

        Intent i = new Intent(getBaseContext(), doneRegisterActivity.class);
        startActivityForResult(i, 0);
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }

I am getting a SERVICE_NOT_AVAILABLE error upon registration, what could be causing this? This is on an Activity.

Bob
  • 22,810
  • 38
  • 143
  • 225
Qasim
  • 1,686
  • 4
  • 27
  • 51
  • I am experimenting with C2DM right now and am also seeing this same SERVICE_NOT_AVAILABLE error in the logs, as well as "DEBUG/C2DMRegistrar(235): [C2DMRegistrar.69] register: http error 404". I saw you accepted the answer saying it may be a server hiccup. Was it something that went away? Server problems? – Mason Lee Aug 25 '11 at 05:03
  • 1
    @Mason it was actually because the Email I was entering was not a valid email, after fixing that problem C2DM was working fine. – Qasim Aug 25 '11 at 21:33
  • Ah! Same here. I had signed up using a mail alias, not a Google account; signup system doesn't care, but C2DM does. Thanks. – Mason Lee Aug 27 '11 at 04:52

1 Answers1

2

From the C2DM page:

The device can't read the response, or there was a 500/503 from the server that can be retried later. The application should use exponential back off and retry.

Probably a server hiccup. (IE, doubtful that it's something on your end). Just to be sure, try using your credentials with one of the sample apps listed on that page, and see if it works there.

Alexander Lucas
  • 22,171
  • 3
  • 46
  • 43