title: Android :Tap on Push Notification does not open Application
body: <p>I have an android app which requires some notifications from my web-server to my android phone . Earlier I used to receive notifications and on tapping the notification , my application used to open . However without anything being changed now , I receive all notifications but I cannot tap on them to open my application anymore . </p>
  
  <p>I have tried checking the code and the manifest for permissions , but dosen't seem to know the problem .</p>
  
  <p>Here are some of the required code files :</p>
  
  <p>AndroidManifest.xml</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.rakibansary.roomautomator"&gt;
  
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
      &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
  
      &lt;permission
          android:name="com.rakibansary.roomautomator.permission.C2D_MESSAGE"
          android:protectionLevel="signature" /&gt;
  
      &lt;uses-permission android:name="com.rakibansary.roomautomator.permission.C2D_MESSAGE" /&gt;
  
  
      &lt;application
  
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme"&gt;
  
          &lt;receiver
              android:name=".receivers.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;category android:name="com.rakibansary.roomautomator" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
          &lt;service android:name=".services.GcmIntentService" /&gt;
  
          &lt;activity
              android:name="com.rakibansary.roomautomator.Splash"
              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;activity android:name=".Welcome"
              android:configChanges="locale"/&gt;
          &lt;activity android:name=".CentralBox" /&gt;
          &lt;activity android:name=".Register"
              android:configChanges="locale"/&gt;
  
          &lt;activity
              android:name="com.rakibansary.roomautomator.Home"
              android:label="@string/title_activity_home" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>GcmBroadcastReceiver.java</p>
  
  <pre><code>package com.rakibansary.roomautomator.receivers;
  
  import android.app.Notification;
  import android.app.NotificationManager;
  import android.app.PendingIntent;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.NotificationCompat;
  import android.util.Log;
  import android.widget.Toast;
  
  import com.rakibansary.roomautomator.CentralBox; // Added from New code
  
  import com.rakibansary.roomautomator.Home;
  import com.rakibansary.roomautomator.R;
  import com.rakibansary.roomautomator.util.Tools;
  
  import org.json.JSONObject;
  
  /**
   * Created by rakib on 5/10/15.
   */
  public class GcmBroadcastReceiver extends BroadcastReceiver {
      private static final String TAG = "GcmBroadcastReceiver";
  
  // Added from new code
  
      public static final String TYPE_DEVICE_STATUS_MODIFIED = "1";
      public static final String TYPE_BATCH_OPERATION = "2";
      public static final String TYPE_DEVICE_DELETED = "3";
      public static final String BOX_ID = "boxid";
  
  // Add Finish
  
  
      @Override
      public void onReceive(Context context, Intent intent) {
          if (Tools.needsLoginOrRegistration(context))
              return;
  
          context.sendBroadcast(new Intent(Home.FILTER_NOTIFICATION_RECEIVER));
  
          Bundle extras = intent.getExtras();
          try {
              String type = extras.getString("type");
              JSONObject data = new JSONObject(extras.getString("data"));
  
              Log.i(TAG, "Push notification received: " + data); // Added from new code
  
  //            if (type.equals("1"))  Commented this and added new If clause below
  
  
              if (type.equals(TYPE_DEVICE_STATUS_MODIFIED))   {
  
  
                  // Added from new code
                  final String boxid = data.getString(BOX_ID);
                  final String mac = data.getString("mac");
                  final boolean powerState = data.getBoolean("ps");
                  final boolean startState = data.getBoolean("ss");
                  final String temperature = data.getString("temp");
                  Intent resultIntent = new Intent(context, Home.class);
                  resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                  resultIntent.putExtra(Home.EXTRA_CENTRAL_BOX_ID, boxid);
                  resultIntent.putExtra(Home.EXTRA_DEVICE_MAC, mac);
                  resultIntent.putExtra(Home.EXTRA_POWER_STATE, powerState);
                  resultIntent.putExtra(Home.EXTRA_START_STATE, startState);
                  resultIntent.putExtra(Home.EXTRA_TEMPERATURE, temperature);
                  PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  
                  // Add finished
  
                  NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
  
                          .setContentIntent(resultPendingIntent)  // Added from new code
                          .setSmallIcon(R.drawable.ic_launcher)
                          .setContentTitle("Device status modified")
                          .setContentText("Device Mac: " + data.getString("mac"))
                          .setStyle(new NotificationCompat.BigTextStyle().bigText(
                                  "Device MAC: " + data.getString("mac") +
                                          "\nPower State: " + (data.getBoolean("ps") ? "On" : "Off") + "\n" +
                                          "Start Sate: " + (data.getBoolean("ss") ? "Running" : "Stopped") + "\n" +
                                          "Temperature: " + data.getString("temp")
                          ));
  
                  NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                  mNotifyMgr.notify(222, mBuilder.build());
              } else if (type.equals(TYPE_BATCH_OPERATION)) {               // Added from new code the if clause
                  String boxid = data.getString("boxid");
                  Tools.saveCentralBox(context, boxid);
  
                  Intent resultIntent = new Intent(context, Home.class);
                  resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                          Intent.FLAG_ACTIVITY_CLEAR_TASK);
  
                  resultIntent.putExtra(Home.EXTRA_CENTRAL_BOX_ID, boxid);
  
  
                  PendingIntent resultPendingIntent = PendingIntent.getActivity(
                          context,
                          0,
                          resultIntent,
                          PendingIntent.FLAG_UPDATE_CURRENT
                  );
  
                  NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                          .setSmallIcon(R.drawable.ic_launcher)
                          .setContentTitle("Batch operation performed!")
                          .setContentText("Tap to view details!")
                          .setAutoCancel(true)
                          .setContentIntent(resultPendingIntent);
  
                  NotificationManager notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                  notifManager.notify(223, mBuilder.build());
              }   else if (type.equals(TYPE_DEVICE_DELETED)) {                // Added the else if  from new code
                  final String boxid = data.getString(BOX_ID);
                  final String mac = data.getString("mac");
                  Tools.deleteDevice(context, boxid, mac);
                  Log.i(TAG, "Device deleted");
                  Intent resultIntent = new Intent(context, Home.class);
                  resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                  resultIntent.putExtra(Home.EXTRA_CENTRAL_BOX_ID, boxid);
                  resultIntent.putExtra(Home.EXTRA_DEVICE_MAC, mac);
                  resultIntent.putExtra(Home.EXTRA_DEVICE_DELETED, true);
                  PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                  NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                          .setContentIntent(resultPendingIntent)
                          .setSmallIcon(R.drawable.ic_launcher)
                          .setContentTitle("Device Deleted")
                          .setContentText("Device Mac: " + data.getString("mac"))
                          .setStyle(new NotificationCompat.BigTextStyle().bigText(
                                  "Device MAC: " + mac + " was just deleted!"
                          ));
                  NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                  mNotifyMgr.notify(224, mBuilder.build());
              }
          } catch (Exception e) {
  
          }
  
      }
  }
  </code></pre>
  
  <p>GcmIntentService.java</p>
  
  <pre><code>package com.rakibansary.roomautomator.services;
  
  import android.app.IntentService;
  import android.content.Intent;
  
  /**
   * Created by rakib on 5/10/15.
   */
  public class GcmIntentService extends IntentService {
  
      public GcmIntentService() {
          super("GcmIntentService");
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
  
      }
  }
  </code></pre>