Ionic 3安卓部分设备进程终止后FCM通知无法接收问题咨询
Fixing FCM Notifications on Oppo/Vivo/Xiaomi When App is Killed (Ionic 3)
I’ve run into this exact problem countless times with Ionic 3 apps targeting these Chinese OEMs—aggressive battery optimization and background process restrictions are almost always the culprit. Let’s break down solutions tailored to the two plugins you’ve tested, plus critical device-specific fixes.
First: Understand the OEM Restrictions
These manufacturers don’t follow standard Android background behavior:
- Oppo: Blocks auto-start of apps by default and kills background processes even if they have FCM listeners. You’ll need to enable "Auto-start" and set battery optimization to "No restrictions".
- Vivo: Requires enabling "Background app refresh" and auto-start permissions. Their battery saver terminates unapproved apps in the background.
- Xiaomi: Uses strict "Autostart" permissions and battery saver rules. Apps not whitelisted get their background processes killed within minutes of being closed.
Solutions for cordova-plugin-firebase
- Verify Configuration: Double-check that your
google-services.jsonis correctly placed in theplatforms/androidfolder and that the plugin is installed with the latest compatible version for Ionic 3. - Handle Background Notifications: Add this listener to your
app.component.tsto catch notifications when the app is killed or in the background:firebase.onNotificationOpen().subscribe((notification) => { if (notification.tap) { // Handle notification tap from killed state console.log('Notification tapped:', notification); } else { // Handle foreground notification } }); - Guide Users to Auto-Start Settings: These permissions aren’t part of standard Android, so create a helper function to open OEM-specific settings:
Call this function on app start to prompt users to enable auto-start.const openAutoStartSettings = () => { const packageName = cordova.application.getPackageName(); let intentUri: string; if (device.platform === 'Android') { switch (device.manufacturer.toLowerCase()) { case 'oppo': intentUri = `intent://settings#Intent;action=android.settings.APPLICATION_DETAILS_SETTINGS;package=${packageName};end`; break; case 'vivo': intentUri = `intent://settings#Intent;action=com.vivo.permissionmanager.activity.BlackListActivity;package=${packageName};end`; break; case 'xiaomi': intentUri = `intent://settings#Intent;action=com.miui.securitycenter.permission.AppPermissionsEditorActivity;package=${packageName};end`; break; } if (intentUri) { cordova.plugins.intent.launchIntent(intentUri, () => {}, () => {}); } } }; - Whitelist Battery Optimization: Instruct users to go to their device’s battery settings, find your app, and set battery optimization to "No restrictions".
Solutions for cordova-plugin-firebasex
This improved fork has better support for modern Android features, making it more reliable for these OEMs:
- Install Compatible Version: For Ionic 3, use a version that works with Cordova 8/9 (e.g.,
^10.0.0):ionic cordova plugin add cordova-plugin-firebasex@10.0.0 --save - Send High-Priority Notifications: Set your FCM payload priority to
highto ensure delivery even when the app is killed:{ "notification": { "title": "Alert", "body": "Your message here" }, "data": { "customKey": "customValue" }, "priority": "high" } - Check Permissions Programmatically: Use the plugin’s built-in methods to verify and request auto-start access:
FirebaseX.isAutoStartEnabled().then((enabled) => { if (!enabled) { FirebaseX.showAutoStartSettings(); // Opens OEM-specific settings } }); - Disable Battery Optimization: Request whitelisting directly via the plugin:
FirebaseX.disableBatteryOptimization().then(() => { console.log('Battery optimization disabled'); }).catch((err) => { console.error('Failed to disable battery optimization:', err); });
Final Tips
- Test on Real Devices: Emulators won’t replicate OEM background restrictions—always use physical Oppo/Vivo/Xiaomi devices for testing.
- Refresh FCM Tokens: Ensure your app refreshes the FCM token on start and that your server uses the latest token for notifications.
- Foreground Service (Last Resort): If all else fails, implement a foreground service to keep your app alive in the background. Note this requires additional permissions and may feel intrusive to users.
内容的提问来源于stack exchange,提问作者Himanshu itmca
相关产品推荐
相关产品推荐

