title: Appcelerator: Use GCM to get a notification, have that notification open the app
body: <p>I've got GCM sending notifications to my phone, and my phone can get them (if the app has already been opened. If it's no longer running, it doesn't open. That's also a problem.)</p>
  
  <p>However, right now I'm focusing on what happens when I click on a notification that I've received. In particular, nothing happens. I've got it set up so that it should open up the app, via intents, but it's not working.</p>
  
  <p>Here's the relevant portion from my app.js:</p>
  
  <pre><code>var senderId = 'XXXXXXXXXX';
  
  var c2dm = require('com.findlaw.c2dm');
  Ti.API.info("module is =&gt; " + c2dm);
  
  Ti.API.info('Registering...');
  c2dm.registerC2dm(senderId, {
      success:function(e) {
          Ti.API.info('JS registration success event: ' + e.registrationId);
  
          var params = {devicecode: e.registrationId, deviceType: "Android"};
          JOURNAL.webApi.webCallPOST(JOURNAL.serviceLocatorModel.urls.Membership, "/registerdevice", params, JOURNAL.registerDeviceComplete, JOURNAL.registerDeviceError);
      },
      error:function(e) {
          Ti.API.error("Error during registration: "+e.error);
  
          var message;
          if(e.error == "ACCOUNT_MISSING") {
              message = "No Google account found; you'll need to add one (in Settings/Accounts) in order to activate notifications";
          } else {
              message = "Error during registration: "+e.error
          }
  
          Titanium.UI.createAlertDialog({
              title: 'Push Notification Setup',
              message: message,
              buttonNames: ['OK']
          }).show();
      },
      callback:function(e) // called when a push notification is received
      {
          Ti.API.info('JS message event: ' + JSON.stringify(e.data));
  
          var intent = Ti.Android.createIntent({
              action: Ti.Android.ACTION_MAIN,
              flags: Ti.Android.FLAG_ACTIVITY_NEW_TASK | Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED,
              className: 'com.geneca.journaling.GenecaJournalingActivity',
              //className: 'org.appcelerator.titanium.TiActivity',
              packageName: 'com.geneca.journaling'
          });
          intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
  
          // This is fairly static: Not much need to be altered here
          var pending = Ti.Android.createPendingIntent({
              activity: Ti.Android.currentActivity,
              intent: intent,
              type: Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
          });
  
          var notification = Ti.Android.createNotification({
              contentIntent: pending,
              contentTitle: 'New message',
              contentText: e.data.message,
              tickerText: "New message"
          });
  
          Ti.Android.NotificationManager.notify(1, notification);
      }
  });
  </code></pre>
  
  <p>And here's the relevant portion from my tiapp.xml</p>
  
  <pre><code>&lt;android xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;manifest&gt;
          &lt;activity android:name="com.geneca.journaling.GenecaJournalingActivity" /&gt;
          &lt;permission android:name="com.geneca.journaling.permission.C2D_MESSAGE" android:protectionLevel="signature"/&gt;
          &lt;uses-permission android:name="com.geneca.journaling.permission.C2D_MESSAGE"/&gt;
  
          &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/&gt;
          &lt;uses-permission android:name="android.permission.WAKE_LOCK"/&gt;
          &lt;application&gt;
              &lt;service android:name="com.findlaw.c2dm.C2DMReceiver"/&gt;
              &lt;receiver
                  android:name="com.google.android.c2dm.C2DMBroadcastReceiver" 
                      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.geneca.journaling"/&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.geneca.journaling"/&gt;
                  &lt;/intent-filter&gt;
              &lt;/receiver&gt;
          &lt;/application&gt;
      &lt;/manifest&gt;
  &lt;/android&gt;
  &lt;modules&gt;
      &lt;module platform="android" version="0.1"&gt;com.findlaw.c2dm&lt;/module&gt;
  &lt;/modules&gt;
  </code></pre>
  
  <p>I've run log cat, and it's getting the notification, and the intent, but it spits this out, and doesn't open the app:</p>
  
  <pre><code>I/ActivityManager(  307): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 pkg=com.geneca.journaling cmp=com.geneca.journaling/.GenecaJournalingActivity bnds=[0,102][720,230] u=0} from pid -1
  W/KeyguardViewMediator(  307): verifyUnlock called when not externally disabled
  W/InputMethodManagerService(  307): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@41c18038 attribute=android.view.inputmethod.EditorInfo@42319798
  </code></pre>
  
  <p>(The middle one doesn't always show up, so I don't think it's really relevant.)</p>
  
  <p>On a side note, if the app isn't open, the log cat gives me <code>Bad notification posted from package com.geneca.journaling.mobile: Couldn't create icon</code> and then a bunch of errors.</p>