“错误:升级到 targetSDK 34 后需要“RECEIVER_EXPORTED”或“RECEIVER_NOT_EXPORTED”以进行 Firebase FCM 应用内调用

问题描述 投票:0回答:1

我最近将应用程序的目标 SDK 从 33 升级到 34。更新后,我开始遇到以下错误:

One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

我的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <!-- Add the following permission on devices running Android 12.0 or later -->
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <!--    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />-->

    <application
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        android:label=""
        android:networkSecurityConfig="@xml/network_security_config"
        android:usesCleartextTraffic="true">

        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:exported="true"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" android:host="" />
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

问题

  • 我应该如何在 AndroidManifest.xml 中配置广播接收器以兼容 API 级别 34?
  • Firebase FCM 集成是否需要任何其他步骤才能与新的目标 API 级别配合使用?

我尝试过的:

检查了 Firebase 配置:确认 Firebase FCM 设置和设置正确且是最新的。

开发环境

  • 工具:AndroidStudio
  • 语言:飞镖
  • flutter_callkeep:0.3.4
android firebase firebase-cloud-messaging android-manifest
1个回答
0
投票

从API 33开始,需要重新检查registerReceiver的所有使用情况,并添加一个标志来标记是否导出

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
        context.registerReceiver(mReceiver, filter, Context.RECEIVER_NOT_EXPORTED);
    } else {
        context.registerReceiver(mReceiver, filter);
    }
© www.soinside.com 2019 - 2024. All rights reserved.