You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

  1. Verify Configuration: Double-check that your google-services.json is correctly placed in the platforms/android folder and that the plugin is installed with the latest compatible version for Ionic 3.
  2. Handle Background Notifications: Add this listener to your app.component.ts to 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
      }
    });
    
  3. Guide Users to Auto-Start Settings: These permissions aren’t part of standard Android, so create a helper function to open OEM-specific settings:
    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, () => {}, () => {});
        }
      }
    };
    
    Call this function on app start to prompt users to enable auto-start.
  4. 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:

  1. 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
    
  2. Send High-Priority Notifications: Set your FCM payload priority to high to ensure delivery even when the app is killed:
    {
      "notification": {
        "title": "Alert",
        "body": "Your message here"
      },
      "data": {
        "customKey": "customValue"
      },
      "priority": "high"
    }
    
  3. 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
      }
    });
    
  4. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 13:07:47