Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>public class C2dmEx extends Activity { static TextView mytext = null; Context context = null; Intent intent = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mytext = (TextView) findViewById(R.id.mytext); mytext.setText("app started"); Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER"); registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); registrationIntent.putExtra("sender","your Mail Id"); startService(registrationIntent); mytext.setText("Grabbing your device registration ID....."); Log.i("Recieve","1"); } } public class C2DMReceiver extends BroadcastReceiver { //private CustomerBean customer = null; private RegisterManager reg = null; private C2dmEx ex = null; int UserId = 0; private boolean auth = false; private CustLogin cl = null; public C2DMReceiver() { cl = new CustLogin(); } @Override public void onReceive(Context context, Intent intent) { Log.i("Recieve","2"); C2dmEx.mytext.setText("Intent Received!"); 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"); if (intent.getStringExtra("error") != null) { C2dmEx.mytext.setText("There was an error with your device registration!"); // Registration failed, should try again later. } else if (intent.getStringExtra("unregistered") != null) { // unregistration done, new messages from the authorized sender will be rejected C2dmEx.mytext.setText("You have been 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. // UserId = customer.getId(); // Log.i("id",String.valueOf(UserId)); String RegId = registration; Log.i("reg",String.valueOf(RegId) ); C2dmEx.mytext.setText("Your registration code is: " + RegId); } } private void handleMessage(Context context, Intent intent) { C2dmEx.mytext.setText("You have been alerted!"); } } </code></pre> <p>and your manifest</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mmp.geopon" android:versionCode="1" android:versionName="0.1"&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".C2dmEx" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;receiver android:name=".C2DMReceiver" android:permission="com.google.android.c2dm.permission.SEND"&gt; &lt;intent-filter&gt; &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt; &lt;category android:name="com.mmp.geopon" /&gt; &lt;/intent-filter&gt; &lt;intent-filter&gt; &lt;action android:name="com.google.android.c2dm.intent.REGISTRATION" /&gt; &lt;category android:name="com.mmp.geopon" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;uses-sdk android:minSdkVersion="8" /&gt; &lt;permission android:name="com.mmp.geopon.permission.C2D_MESSAGE" android:protectionLevel="signature" /&gt; &lt;uses-permission android:name="com.mmp.geopon.permission.C2D_MESSAGE" /&gt; &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt; &lt;/manifest&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload