FCM notifications not receiving in app downloaded from playstore but debug version works normally?

Viewed 606

I recently published by app in play store. It was not receiving fcm push notification (provided I'm using default channel in fcm console) but receiving fcm test notification to the same device.

The debug version of the app was receiving fcm notifications normally and also receiving fcm test notifications normally.

Please correct any changes in code !

Thanks in Advance !

Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.github.chillmonk2.mycollege"
    android:versionCode="1"
    android:versionName="Release">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/icon_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/icon_launcher_round"
        android:supportsRtl="true"

        android:usesCleartextTraffic="true"
        android:theme="@style/AppTheme">
        <activity android:name=".HomeActivity"
            android:theme="@style/AppTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:theme="@style/AppTheme">

        </activity>
        <activity
            android:name=".EditProfile"
            android:theme="@style/AppTheme"></activity>
        <activity
            android:name=".ShowProfileActivity"
            android:theme="@style/AppTheme"></activity>
        <activity
            android:name=".SettingsActivity"
            android:theme="@style/AppTheme"></activity>
        <service
            android:name=".MyFirebaseMessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/rvr" />
        <!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
             notification message.  for more. -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/colorAccent" />
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="@string/default_notification_channel_id"/>

        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />

    </application>


</manifest>

MyFirebaseMessagingService.java

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        showNotification(remoteMessage.getNotification().getBody());
    }

    private void showNotification(String body) {
        Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
        Notification notification = new NotificationCompat.Builder(this,getString(R.string.default_notification_channel_id))
                .setSmallIcon(R.drawable.rvr)
                .setContentTitle("RVRJC")
                .setSound(uri)
                .setContentText(body)
                .setContentIntent(pi)
                .setAutoCancel(true)
                .build();

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);
    }

    @Override
    public void onNewToken(String s) {
        super.onNewToken(s);
        Log.d("FCM Token", "Refreshed token: " + s);

        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.

    }
}

build.gradle app

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.github.chillmonk2.mycollege"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 3
        versionName "1.5.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        resConfigs "en"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false



        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.multidex:multidex:2.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-auth:17.0.0'
    implementation 'com.google.firebase:firebase-database:17.0.0'
    implementation 'com.google.firebase:firebase-firestore:19.0.0'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'
    implementation 'com.firebaseui:firebase-ui-auth:5.0.0'
    implementation 'com.firebaseui:firebase-ui-database:5.0.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'org.jsoup:jsoup:1.10.3'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

Build.gradle project File

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath 'com.google.gms:google-services:4.2.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        //crashlytics Plugin
        classpath 'io.fabric.tools:gradle:1.29.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

0 Answers
Related