0

I followed the tutorial from this link http://blog.nkdroidsolutions.com/android-push-notification-example-using-firebase/ but I am not not receiving any notification on my device.

I checked and tried these links too, but could not find a solution android - Firebase Notification Push Notification not working Push Notification not Received in android

In my firebase console, the notification sent is 0. Here is my androidManifest File

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ather.healthapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WIFI" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity android:name=".MainActivity" />
    <activity android:name=".LoginActivity" />
    <activity android:name=".SplashScreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".SignUpScreen">
        <intent-filter>
            <action android:name="com.example.ather.healthapp.SignUpScreen" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>



    <activity android:name=".LoginActivity_New" />
    <activity android:name=".ActivityUserProfile" />

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity
        android:name=".MapActivity"
        android:label="@string/title_activity_map" />
    <activity android:name=".TestActivity" />
    <activity android:name=".stDisplayListView" />
    <activity android:name=".DoctorAppointment" />
    <activity android:name=".todelete" />
    <activity android:name=".TestGoogleSignIn" />
    <activity android:name=".UserHistoryActivity" />
    <activity android:name=".UserMedicineAndTestActivity" />

    <service android:name="firebaseconnection.FirebaseIDService"
        android:enabled="true"
        android:exported="true"
        >
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
    <service android:name="firebaseconnection.MyFirebaseMessagingService"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"

                />
        </intent-filter>
    </service>

    <activity android:name=".UserTestAndMedicine"></activity>
</application>

The gradle file is as follows

apply plugin: 'com.android.application'


android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
    applicationId "com.example.ather.healthapp"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

 }
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(path: ':volley')
repositories {
    mavenCentral()
}
// this line must be included to integrate with Firebase
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.jakewharton:butterknife:8.1.0'
compile 'com.google.android.gms:play-services-auth:9.6.1'
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.sothree.slidinguppanel:library:3.0.0'
compile 'com.android.support:design:24.2.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.6.1'
}

apply plugin: 'com.google.gms.google-services'

Firebase Messaging Service file

package FirebaseConnection;

import android.util.Log;

import com.google.firebase.messaging.RemoteMessage;
public class FirebaseMessagingService extends      
com.google.firebase.messaging.FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());
    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

}

}

And the Firebase ID Service

package FirebaseConnection;

import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

public class FirebaseIDService extends FirebaseInstanceIdService {
private static final String TAG = "FirebaseIDService";

@Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);

    // TODO: Implement this method to send any registration to your app's servers.
    sendRegistrationToServer(refreshedToken);
}

/**
 * Persist token to third-party servers.
 *
 * Modify this method to associate the user's FCM InstanceID token with any server-side account
 * maintained by your application.
 *
 * @param token The new token.
 */
private void sendRegistrationToServer(String token) {
    // Add custom implementation, as needed.
}
}

Any help would be appreciated.

Regards

Community
  • 1
  • 1
AIS
  • 297
  • 1
  • 4
  • 16
  • Can you share MyFirebaseMessageService and FirebaseIDService class code? – rogerwar Jan 07 '17 at 15:28
  • Are you getting any exception? – rogerwar Jan 07 '17 at 15:29
  • Do you have any `data` along with your notification? Please post the message you send as your notification. – Reaz Murshed Jan 07 '17 at 15:35
  • There is no exception, and we are sending it though firebase console a simple hello message with no data – AIS Jan 08 '17 at 08:47
  • @rogerwar Added files as suggested. – AIS Jan 08 '17 at 08:53
  • did u created [Firebase project](https://console.firebase.google.com/?pli=1) and added the [config file](http://support.google.com/firebase/answer/7015592) to your app dir ? – Rissmon Suresh Jan 08 '17 at 09:23
  • also post your server side script code that you probaly calling from sendRegistrationToServer to send token to server, and notification trigger method in server side script to send push notification. – rogerwar Jan 08 '17 at 15:11
  • Same problem here sending from Firebase Console for testing. Any clues ? – Mik Jan 11 '18 at 12:29
  • I solved it by removing my firebase project, creating a GCM project and then convert it to FCM. Also don't forget to add the certificate SHA footprint – Mik Jan 14 '18 at 00:14

1 Answers1

0

The problem is the name of your class!

Manifest: MyFirebaseMessagingService

Service class: FirebaseMessagingService

the name of the two must be the same

Mike Brian Olivera
  • 1,414
  • 1
  • 16
  • 21