0

I am unable to receive Pus notifications from Google functions when I swipe the app from recent apps on my One Plus 3T,However It's working perfectly on the Nexus Emulators.

Here is my Google Functions code

//import firebase functions modules
const functions = require('firebase-functions');
//import admin module
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);


// Listens for new messages added to messages/:pushId
exports.pushNotification = functions.database.ref('notificationRequests/{pushId}').onWrite( event => {

    console.log('Push notification event triggered');



    //  Grab the current value of what was written to the Realtime Database.
    var valueObject = event.data.val();



  // Create a notification
    const payload = {
       data: {
            title:"New Reminder",
            body: "You have a new Reminder" ,
            sound: "default"
        },


    };

  //Create an options object that contains the time to live for the notification and the priority
    const options = {
        priority: "high",
        timeToLive: 60 * 60 * 24
    };


    return admin.messaging().sendToTopic(valueObject.receiverUID, payload, options)
        .then(function(response){
            console.log("Succesfull",response);
        })
        .catch(function(error){
            console.log("Error sending message",error);
        })

});

Here is the FCM Call backService code whhich features, OnMessageReceived

public class FCMCallbackService extends FirebaseMessagingService {
    private static final String TAG = "FCMCallbackService";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        /*Log.d(TAG, "From:" + remoteMessage.getFrom());
        Log.d(TAG, "Message Body:" + remoteMessage.getNotification().getBody());
        //sendNotification(remoteMessage.getNotification());
        if (remoteMessage == null)
            return;
        if (remoteMessage.getNotification() != null) {
            Log.i(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
        }*/
        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {
            Log.i(TAG, "Data Payload: " + remoteMessage.getData().toString());
            String DataTitle = remoteMessage.getData().get("title");
            String body = remoteMessage.getData().get("body");
            Log.i(TAG, "Data Payload: " + DataTitle);
            sendNotification(DataTitle,body);

          //  sendNotification(remoteMessage.getData().toString());
    }}

    private void sendNotification(String title,String body) {
        int color = getResources().getColor(R.color.colorPrimary);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setContentTitle(title)
                .setContentText(body)
                .setAutoCancel(true)
                .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
                .setColor(color)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(body))
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager)
                getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, builder.build());
    }
}

Service in Manifest

<service android:name=".FCMCallbackService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

And here are my dependencies,I am using old version of FIrebase Messaging as for some reason ,I get error "Cannot resolve.." if I use 10.4.1 .(Yes, I have updated Google play services and repository)

compile 'com.google.firebase:firebase-auth:9.0.2'
compile 'com.android.support:design:25.1.0'
compile 'com.google.firebase:firebase-database:9.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:gridlayout-v7:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.google.firebase:firebase-messaging:9.0.1'

compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.firebaseui:firebase-ui-database:0.4.1'
KENdi
  • 7,576
  • 2
  • 16
  • 31
shivam dhuria
  • 69
  • 1
  • 9
  • Possible duplicate of [Android app not receiving Firebase Notification when app is stopped from multi-task tray](https://stackoverflow.com/questions/39504805/android-app-not-receiving-firebase-notification-when-app-is-stopped-from-multi-t) – AL. Aug 12 '17 at 05:40

1 Answers1

0

You need to whitelist your app in the one plus settings. Chinese manufacturers block apps from running in the background. You would face a simillar situation in Xiaomi, Vivo, gionee, Oppo etc.

Sarthak Mishra
  • 1,033
  • 1
  • 11
  • 27