Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid GCM basic implementation
    primarykey
    data
    text
    <p><strong>UPDATE:</strong> I fixed the problems in the code below so this makes a nice basic working example of how to use <code>GCM</code></p> <hr> <p>So, I'm trying to implement Android <code>GCM</code> into my app. Here are the relevant parts I've added to the manifest:</p> <pre><code>&lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="20" /&gt; &lt;permission android:name=".permission.C2D_MESSAGE" android:protectionLevel="signature" /&gt; &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt; &lt;uses-permission android:name=".permission.C2D_MESSAGE" /&gt; &lt;uses-permission android:name="android.permission.WAKE_LOCK"/&gt; &lt;uses-permission android:name="android.permission.GET_ACCOUNTS"/&gt; </code></pre> <p>...</p> <pre><code>&lt;receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" 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;action android:name="com.google.android.c2dm.intent.REGISTRATION" /&gt; &lt;category android:name="com.badbob.app.gmctestapp" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;service android:name=".GCMIntentService" /&gt; </code></pre> <p>I've added the following code to the onCreate of my main activity:</p> <pre><code> GCMRegistrar.checkDevice( this ); GCMRegistrar.checkManifest( this ); final String regId = GCMRegistrar.getRegistrationId( this ); if( regId.equals( "" ) ) { GCMRegistrar.register( this, GCM_SENDER_ID ); } else { Log.v( LOG_TAG, "Already registered" ); } </code></pre> <p>I've also created the <code>GCMIntenetService</code> class like so:</p> <pre><code>public class GCMIntentService extends GCMBaseIntentService { private static final String LOG_TAG = "GetAClue::GCMIntentService"; public GCMIntentService() { super( GCM_SENDER_ID ); // TODO Auto-generated constructor stub Log.i( LOG_TAG, "GCMIntentService constructor called" ); } @Override protected void onError( Context arg0, String errorId ) { // TODO Auto-generated method stub Log.i( LOG_TAG, "GCMIntentService onError called: " + errorId ); } @Override protected void onMessage( Context arg0, Intent intent ) { // TODO Auto-generated method stub Log.i( LOG_TAG, "GCMIntentService onMessage called" ); Log.i( LOG_TAG, "Message is: " + intent.getStringExtra( "message" ) ); } @Override protected void onRegistered( Context arg0, String registrationId ) { // TODO Auto-generated method stub Log.i( LOG_TAG, "GCMIntentService onRegistered called" ); Log.i( LOG_TAG, "Registration id is: " + registrationId ); } @Override protected void onUnregistered( Context arg0, String registrationId ) { // TODO Auto-generated method stub Log.i( LOG_TAG, "GCMIntentService onUnregistered called" ); Log.i( LOG_TAG, "Registration id is: " + registrationId ); } } </code></pre> <p>When I run this I get this in <strong>LogCat</strong>:</p> <pre><code>07-11 11:28:46.340: V/GCMRegistrar(27435): Registering receiver 07-11 11:28:46.370: D/GCMRegistrar(27435): resetting backoff for com.badbob.app.getacluebeta 07-11 11:28:46.380: V/GCMRegistrar(27435): Registering app com.badbob.app.getacluebeta of senders 128205395388 </code></pre> <p>From what I've gleaned from other posts I should get a registration ID in <code>LogCat</code> but I"m not. Also <code>onRegistered()</code> in <code>GCMIntentService</code> never gets called. So what am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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