I have integrated Firebase Cloud Messaging (FCM) in my Android app using Java, and I am able to display custom notifications when the app is in the foreground. However, when the app is in the background or killed, the custom notifications do not appear.
I understand that in the background or when the app is closed, FCM uses a “data-only” message, which requires the app to handle the notification manually. I’ve tried implementing custom notifications for these cases, but they are not showing up.
Is there a way to ensure that custom notifications work even when the app is in the background or has been killed? If so, could you provide guidance on the correct implementation or alternative methods to achieve this?
Ashley Joff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
this code starts your service every time user device reboot
create a class like this
public class AutoStart extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent intentService = new Intent(context, YourService.class);
context.startForegroundService(intentService);
}
}
and in manifest.xml in application tag add this
<receiver
android:name=".AutoStart"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <!-- on start up os -->
</intent-filter>
</receiver>
your service is get data from FCM and create notifications