Android Open Source - GCMNotifier Main Activity






From Project

Back to project page GCMNotifier.

License

The source code is released under:

MIT License

If you think the Android project GCMNotifier listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.trygveaa.gcmnotifier;
/*from   ww w .jav  a2 s. c  om*/
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.google.android.gcm.GCMRegistrar;

public class MainActivity extends Activity {

  private static final String TAG = "GCMNotifier";
  private static final String SENDER_ID = "";

  private EditText registeredId;
  private Button preferences;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    registeredId = (EditText) findViewById(R.id.registered_id);
    preferences = (Button) findViewById(R.id.button_preferences);

    preferences.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        startActivity(new Intent(MainActivity.this, SettingsActivity.class));
      }
    });

    GCMRegistrar.checkDevice(this);
    final String regId = GCMRegistrar.getRegistrationId(this);
    if (regId.equals("")) {
      GCMRegistrar.register(this, SENDER_ID);
    } else {
      Log.v(TAG, "Already registered with id: " + regId);
      registeredId.setInputType(InputType.TYPE_NULL);
      registeredId.setText(regId);
    }
  }
}




Java Source Code List

com.trygveaa.gcmnotifier.GCMIntentService.java
com.trygveaa.gcmnotifier.MainActivity.java
com.trygveaa.gcmnotifier.MessageReceiver.java
com.trygveaa.gcmnotifier.SettingsActivity.java