Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 20th, 2012  |  syntax: None  |  size: 3.71 KB  |  views: 144  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. checkNotNull(SENDER_ID, "SENDER_ID");
  2.  
  3. GCMRegistrar.checkDevice(this);
  4. GCMRegistrar.checkManifest(this);
  5.  
  6. TextView mDisplay = (TextView) findViewById(R.id.display);
  7.  
  8. String regId = "";
  9.  
  10. if (!GCMRegistrar.isRegistered(this))
  11. {
  12.     mDisplay.setText("registering");
  13.     GCMRegistrar.register(this, SENDER_ID);
  14.  
  15.     regId = GCMRegistrar.getRegistrationId(this);
  16.     String url = "localhost/Google-Cloud-Messaging-Server-Test/registration.php?regId=" + regId;
  17.  
  18.     Log.i(TAG, "registration url: " + url);
  19.     HttpRequest httprequest = new HttpRequest(url);
  20. }
  21. else
  22. {
  23.     regId = GCMRegistrar.getRegistrationId(this);
  24.  
  25.     mDisplay.setText(regId);
  26.     Log.v(TAG, "Already registered");
  27.  
  28.     GCMRegistrar.unregister(this);
  29. }
  30.        
  31. regId = GCMRegistrar.getRegistrationId(this);
  32. String url = "localhost/Google-Cloud-Messaging-Server-Test/registration.php?regId=" + regId;
  33.        
  34. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  35. package="com.codeglue.google.cloud.messaging.test"
  36. android:versionCode="1"
  37. android:versionName="1.0" >
  38.  
  39. <uses-sdk
  40.     android:minSdkVersion="10"
  41.     android:targetSdkVersion="15" />
  42.  
  43. <permission
  44.     android:name="com.codeglue.google.cloud.messaging.test.permission.C2D_MESSAGE"
  45.     android:protectionLevel="signature" />
  46.  
  47. <uses-permission android:name="com.codeglue.google.cloud.messaging.test.permission.C2D_MESSAGE" />
  48. <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  49. <uses-permission android:name="android.permission.WAKE_LOCK" />
  50. <uses-permission android:name="android.permission.INTERNET" />
  51. <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
  52.  
  53. <application
  54.     android:icon="@drawable/ic_launcher"
  55.     android:label="@string/app_name" >
  56.  
  57.     <activity
  58.         android:name=".MainActivity"
  59.         android:label="@string/app_name" >
  60.  
  61.         <intent-filter>
  62.             <action android:name="android.intent.action.MAIN" />
  63.             <category android:name="android.intent.category.LAUNCHER" />
  64.         </intent-filter>
  65.     </activity>
  66.  
  67.     <receiver
  68.         android:name="com.google.android.gcm.GCMBroadcastReceiver"
  69.         android:permission="com.google.android.c2dm.permission.SEND" >
  70.         <intent-filter>
  71.             <action android:name="com.google.android.c2dm.intent.RECEIVE" />
  72.             <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
  73.  
  74.             <category android:name="com.codeglue.google.cloud.messaging.test" />
  75.         </intent-filter>
  76.     </receiver>
  77.  
  78.     <service android:name=".GCMIntentService" />
  79.  
  80. </application>
  81.  
  82. </manifest>
  83.        
  84. <uses-permission android:name="android.permission.INTERNET"/>
  85.      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  86.      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  87.      <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
  88. <uses-permission android:name="android.permission.WAKE_LOCK"/>
  89. <permission
  90.     android:name="you_package_name.permission.C2D_MESSAGE"
  91.     android:protectionLevel="signature" />
  92. <uses-permission
  93.     android:name="you_package_name.permission.C2D_MESSAGE" />
  94. <!-- This app has permission to register and receive data message. -->
  95. <uses-permission
  96.     android:name="com.google.android.c2dm.permission.RECEIVE" />
  97.        
  98. <receiver
  99.         android:name="com.google.android.gcm.GCMBroadcastReceiver"
  100.         android:permission="com.google.android.c2dm.permission.SEND" >
  101.         <intent-filter>
  102.             <!-- Receives the actual messages. -->
  103.             <action android:name="com.google.android.c2dm.intent.RECEIVE" />
  104.             <!-- Receives the registration id. -->
  105.             <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
  106.             <category android:name="you_package_name" />
  107.          </intent-filter>
  108.     </receiver>
clone this paste RAW Paste Data