I am receiving the notification when the app is in foreground and background. But when I close the app no notification is received.
This is my manifest declaration
<service android:name="com.vfi.fcm.AppInstanceIDListenerService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name="com.vfi.fcm.AppFcmListenerService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
This is the FCM listener class
public class AppFcmListenerService extends FirebaseMessagingService {
private static final String TAG = "FCM - Msg";
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map<String, String> data = remoteMessage.getData();
Set keys = data.keySet();
for (Iterator i = keys.iterator(); i.hasNext(); ) {
String key = (String) i.next();
Log.e("key",key);
String value = (String) data.get(key);
sendNotification(null, value);
Log.e("value",value);
}
}
private void sendNotification(String type, String message) {
Random random = new Random();
int Unique_Integer_Number = random.nextInt(9999 - 1000) + 1000;
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(), Unique_Integer_Number, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
builder.setContentTitle(AppControl.getInstance().getAppName());
builder.setContentText(message);
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
builder.setSound(defaultSoundUri);
builder.setAutoCancel(true);
builder.setContentIntent(pendingIntent);
builder.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message));
nManager.notify(AppControl.getInstance().getAppName(), Unique_Integer_Number, builder.build());
}
I am testing it on Leeco 2 device. Notification is not received when app is closed.
I have tried the solutions available on this Firebase background but none of it solves my issue.
This is my payload
{
"data": {
"Message": "great match!"
},
"to": "fcm-id"
}