title: Firebase Cloud Messaging - onMessageReceived not working
body: <p>I want to make a simple notification feature in my app. I followed <a href="https://www.youtube.com/watch?v=mz4VcuR0-qA" rel="nofollow noreferrer">this</a> YouTube video and both of these Firebase documentation URLs <a href="https://firebase.google.com/docs/cloud-messaging/android/first-message" rel="nofollow noreferrer">1</a> and <a href="https://firebase.google.com/docs/cloud-messaging/android/receive" rel="nofollow noreferrer">2</a> plus the Firebase tool assistant in Android Studio (which says I'm connected to Firebase). For some reason, following these steps and documents on my older app (which code is posted below), it won't allow me to receive notifications. However, if I follow the same steps on a brand new app it works perfectly. I tested both apps on the same physical device and environment in the background, active and terminated states. Every time the new demo app I created works with no issue but my older app which I want notifications in does not work. Both tested without getting the device ID. I do not even get any error logs or any TAG log. I think one of my compiled projects is interfering, not sure exactly what but I might have to look there.</p>
  
  <p>I also checked out all these SO posts already: <a href="http://android%20-%20FireBase%20Cloud%20Messaging%20Not%20Working%20-%20Stack%20Overflow" rel="nofollow noreferrer">1</a><a href="http://android%20-%20Firebase%20cloud%20messaging%20notification%20not%20received%20by%20..." rel="nofollow noreferrer">2</a><a href="http://Firebase%20notification%20not%20working%20on%20Android%20VIRTUAL%20devices%20..." rel="nofollow noreferrer">3</a> and more</p>
  
  <p>PS. I removed my package name below, I checked multiple times on FireBase and they match so I know that is not the issue. However, my new demo app's FireBase shows that my app connected but my older app's FireBase did not. Also, I've set a bounty before and still running into the same issue.</p>
  
  <p>Here's my problematic code:</p>
  
  <p>Notification.java (its a service like the documentation asks)</p>
  
  <pre><code>public class Notification extends FirebaseMessagingService {
  public Notification() {
  }
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
      showNotification(remoteMessage.getData().get("message"));
  
      Log.d("FMC", "Message Notification Body: " + remoteMessage.getNotification().getBody());
  }
  
  private void showNotification(String message) {
      Intent i=new Intent(this, SplashScreen.class);
      i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  
      PendingIntent pendingIntent=PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
      NotificationCompat.Builder builder=new NotificationCompat.Builder(this)
              .setAutoCancel(true)
              .setContentTitle("FCM TITLE").setContentText(message)
              .setSmallIcon(R.drawable.pt_icon)
              .setDefaults(android.app.Notification.DEFAULT_ALL)
              .setContentIntent(pendingIntent);
  
      NotificationManager notificationManager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
      notificationManager.notify(0,builder.build());
  }
  }
  </code></pre>
  
  <blockquote>
    <p>Notice I do not even get a log in the notification.java above.</p>
  </blockquote>
  
  <p><strong>Project.gradle</strong></p>
  
  <pre><code>buildscript {
  repositories {
      jcenter()
      maven {
          url 'https://maven.google.com/'
          name 'Google'
      }
  }
  dependencies {
      classpath 'com.android.tools.build:gradle:3.0.1'
      classpath 'com.google.gms:google-services:3.2.0'
  
      // NOTE: Do not place your application dependencies here; they belong
      // in the individual module build.gradle files
  }
  }
  
  allprojects {
  repositories {
      jcenter()
  
      maven { url "https://jitpack.io" }
      maven { url 'https://maven.google.com' }
      google()
  }
  }
  
  task clean(type: Delete) {
  delete rootProject.buildDir
  }
  </code></pre>
  
  <p><strong>app.gradle</strong></p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
  compileSdkVersion 26
  
  defaultConfig {
  
      minSdkVersion 16
      targetSdkVersion 26
      versionCode 16
      versionName "2.6"
  }
  dexOptions {
      jumboMode = true
  }
  buildTypes {
      release {
          minifyEnabled false
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      }
  }
  //Code below is added to fix random error ("Fix the issues identified by lint")
  lintOptions {
      abortOnError false
  }
  productFlavors {
  }
  }
  
  dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  //compile project(path: ':backend', configuration: 'android-endpoints')
  //Removed the 0.2.+
  compile 'com.daprlabs.aaron:cardstack:0.3.1-beta0'
  //noinspection GradleCompatible
  compile 'com.android.support:appcompat-v7:25.4.0'
  compile "com.android.support:appcompat-v7:19.0.+"
  compile 'com.android.support:design:23.4.0'
  compile 'com.android.support:recyclerview-v7:23.4.0'
  compile 'com.android.support:cardview-v7:23.4.0'
  
  compile 'com.github.danylovolokh:video-player-manager:0.2.0'
  compile 'com.github.danylovolokh:list-visibility-utils:0.2.0'
  
  
  
  implementation 'com.android.support:appcompat-v7:26.1.0'
  implementation 'com.google.firebase:firebase-messaging:11.8.0'
  compile 'com.google.firebase:firebase-core:11.8.0'
  
  
  compile 'com.orhanobut:dialogplus:1.11@aar'
  
  
  compile 'com.nineoldandroids:library:2.4.0'
  compile files('libs/sinch-android-rtc-3.9.14.jar')
  compile 'com.amazonaws:aws-android-sdk-s3:2.4.4'
  compile 'com.github.chrisbanes:PhotoView:1.2.6'
  compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.5.0'
  compile 'com.github.amlcurran.showcaseview:library:5.4.3'
  compile 'com.github.d-max:spots-dialog:0.7@aar'
  compile 'com.victor:lib:1.0.4'
  compile 'com.github.bumptech.glide:glide:3.5.2'
  compile 'com.squareup.picasso:picasso:2.5.2'
  compile 'com.android.support:recyclerview-v7:23.0.0'
  compile 'me.grantland:autofittextview:0.2.0'
  compile 'com.wang.avi:library:1.0.5'
  compile 'com.nineoldandroids:library:2.4.0'
  compile 'com.braintreepayments.api:drop-in:2.3.8'
  compile 'com.braintreepayments.api:braintree:2.3.9'
  compile 'com.loopj.android:android-async-http:1.4.9'
  compile 'com.getbase:floatingactionbutton:1.10.1'
  compile 'com.mxn.soul:flowingdrawer-core:1.2.2'
  compile 'com.github.rengwuxian:MaterialEditText:2.1.4'
  compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
  compile 'net.gotev:uploadservice:3.2.5'
  compile 'in.srain.cube:ultra-ptr:1.0.11'
  compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
  testCompile 'junit:junit:4.12'
  //implementation 'com.android.support:appcompat-v4:23.+'
  }
  
  
  apply plugin: 'com.google.gms.google-services'
  </code></pre>
  
  <p><strong>AndroidManifest.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"&gt;
  
  &lt;uses-feature
      android:name="android.hardware.microphone"
      android:required="false" /&gt;
  
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;!--
  so the app can be found on tablets Google Play
  
  &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;
  --&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.RECORD_AUDIO" /&gt;
  &lt;uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /&gt;
  &lt;!-- &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/&gt; --&gt;
  &lt;!-- &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt; --&gt;
  &lt;!-- &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt; --&gt;
  
  &lt;grant-uri-permission
      android:path="string"
      android:pathPattern="string"
      android:pathPrefix="string" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/_icon"
      android:label=""
      android:supportsRtl="true"
      android:theme="@style/Theme.AppCompat.Light.NoActionBar"
      tools:node="replace"&gt;
      &lt;activity android:name=".SplashScreen"&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;service android:name=".Notification"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
  
      &lt;!-- &amp;lt;!&amp;ndash; --&gt;
      &lt;!-- Set custom default icon. This is used when no icon is set for incoming notification messages. --&gt;
      &lt;!-- See README() for more. --&gt;
      &lt;!-- &amp;ndash;&amp;gt; --&gt;
      &lt;!-- &lt;meta-data --&gt;
      &lt;!-- android:name="com.google.firebase.messaging.default_notification_icon" --&gt;
      &lt;!-- android:resource="@drawable/pt_icon" /&gt; --&gt;
      &lt;!-- &amp;lt;!&amp;ndash; --&gt;
      &lt;!-- Set color used with incoming notification messages. This is used when no color is set for the incoming --&gt;
      &lt;!-- notification message. See README() for more. --&gt;
      &lt;!-- &amp;ndash;&amp;gt; --&gt;
      &lt;!-- &lt;meta-data --&gt;
      &lt;!-- android:name="com.google.firebase.messaging.default_notification_color" --&gt;
      &lt;!-- android:resource="@color/colorAccent" /&gt; --&gt;
  
      &lt;activity android:name=".SignInForm" /&gt;
      &lt;activity android:name=".SignUpPage" /&gt;
      &lt;activity android:name=".SellerFillOutForm" /&gt;
      &lt;activity android:name=".BuyerFillOutForm" /&gt;
      &lt;activity
          android:name=".BuyerHomePage"
          android:label="@string/title_activity_buyer_home_page" /&gt;
  
      &lt;action android:name="android.intent.action.VIEW" /&gt;
  
      &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
  
      &lt;data android:scheme="http" /&gt;
  
      &lt;activity android:name=".VideoPlayerActivity" /&gt;
      &lt;activity android:name=".BackgroundTask" /&gt;
  
      &lt;service
          android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
          android:enabled="true" /&gt;
  
      &lt;activity android:name=".EnterCreditCard" /&gt;
      &lt;activity android:name=".PickMeeting" /&gt;
      &lt;activity android:name=".HowBillingWorks" /&gt;
      &lt;activity android:name=".ReBillingPlan" /&gt;
      &lt;activity android:name=".PayBill" /&gt;
      &lt;activity
          android:name=".Buyer_Home_Page"
          android:configChanges="locale|orientation" /&gt;
      &lt;activity android:name=".Seller_Home_Page" /&gt;
      &lt;activity android:name=".ProductList" /&gt;
      &lt;activity android:name=".EditProduct" /&gt;
      &lt;activity android:name=".EditSellerAccount" /&gt;
      &lt;activity android:name=".EditBuyerAccount" /&gt;
      &lt;activity android:name=".Video_Calling.incomingVideoCall" /&gt;
      &lt;activity android:name=".Video_Calling.CallScreenActivity" /&gt;
      &lt;activity android:name=".SellerAnalytics" /&gt;
      &lt;activity android:name=".Swipe_Layout.SwipeLayout" /&gt;
      &lt;activity android:name=".Swipe_Layout.PopUpActivity" /&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <blockquote>
    <p><strong>Working code below (the app I made just to test my steps and works 100%):</strong></p>
  </blockquote>
  
  <p><strong>Notifaction.java</strong></p>
  
  <pre><code>import android.app.Notification;
  import android.app.NotificationManager;
  import android.app.PendingIntent;
  import android.app.Service;
  import android.content.Intent;
  import android.os.IBinder;
  import android.support.v4.app.NotificationCompat;
  import android.util.Log;
  
  import com.google.firebase.messaging.FirebaseMessagingService;
  import com.google.firebase.messaging.RemoteMessage;
  
  import static android.content.ContentValues.TAG;
  
  public class Notifaction extends FirebaseMessagingService {
  public Notifaction() {
  }
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
      showNotification(remoteMessage.getData().get("message"));
  }
  
  private void showNotification(String message) {
      Intent i=new Intent(this,MainActivity.class);
      i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  
      PendingIntent pendingIntent=PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
      NotificationCompat.Builder builder=new NotificationCompat.Builder(this)
              .setAutoCancel(true)
              .setContentTitle("FCM TITLE").setContentText(message)
              .setSmallIcon(R.drawable.ic_launcher_background)
              .setDefaults(Notification.DEFAULT_ALL)
              .setContentIntent(pendingIntent);
  
      NotificationManager notificationManager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
      notificationManager.notify(0,builder.build());
  }
  }
  </code></pre>
  
  <p><strong>AndroidManiest.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package=""&gt;
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".MainActivity"&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;service
          android:name=".Notifaction"&gt;
          &lt;intent-filter&gt;
              &lt;action 
  android:name="com.google.firebase.MESSAGING_EVENT"/&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
  
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>app.gradle</strong></p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
  compileSdkVersion 26
  defaultConfig {
      applicationId ""
      minSdkVersion 14
      targetSdkVersion 26
      versionCode 1
      versionName "1.0"
      testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }
  buildTypes {
      release {
          minifyEnabled false
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      }
  }
  }
  
  dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation 'com.android.support:appcompat-v7:26.1.0'
  implementation 'com.google.firebase:firebase-messaging:11.8.0'
  compile 'com.google.firebase:firebase-core:11.8.0'
  implementation 'com.android.support.constraint:constraint-layout:1.0.2'
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'com.android.support.test:runner:1.0.1'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
  }
  
  
  apply plugin: 'com.google.gms.google-services'
  </code></pre>
  
  <p><strong>Project.grdle</strong></p>
  
  <pre><code>    // Top-level build file where you can add configuration options common to all sub-projects/modules.
  
  buildscript {
  
  repositories {
      google()
      jcenter()
  }
  dependencies {
      classpath 'com.android.tools.build:gradle:3.0.1'
      classpath 'com.google.gms:google-services:3.2.0'
  
      // NOTE: Do not place your application dependencies here; they 
  belong
      // in the individual module build.gradle files
  }
  }
  
  allprojects {
  repositories {
      google()
      jcenter()
  }
  }
  
  task clean(type: Delete) {
  delete rootProject.buildDir
  }
  </code></pre>
  
  <p>Also, I added the .json file to both projects. Here is a screenshot:
  <a href="https://i.stack.imgur.com/tVOwE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tVOwE.png" alt="link"></a>.</p>