Rah*_*ati 232

Android 12 要求您在主要 Activity 中添加一段代码

  1. 转到您的项目文件夹并打开 AndroidManifest.xml 文件

  2. 在活动中添加以下代码

    android:exported="true"

参考:

   <activity
        android:name=".MainActivity"
        android:exported="true"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme">
    </activity>
Run Code Online (Sandbox Code Playgroud)

  • 需要明确的是,这个答案并不好。您在带有意图过滤器的每个活动以及每个服务上都需要此属性。再次感谢 Android 带来的那些无用的更新,破坏了全球数以百万计的部署!你们是冠军! (63认同)
  • 为什么需要它?`android:exported="true"` 是什么意思/做什么? (9认同)
  • 该属性必须在 &lt;activity&gt; 标记内设置。 (4认同)
  • 我添加了 `android:exported="true"` 但它仍然给出同样的问题 (4认同)
  • 另请检查您的依赖项是否有更新。我的情况是 local_notifications 插件导致了错误,因为旧的插件版本没有设置导出的属性。 (3认同)
  • @instanceof 有关该属性的更多信息可以在 https://medium.com/androiddevelopers/lets-be-explicit-about-our-intent-filters-c5dbe2dbdce0 找到 (2认同)

eda*_*lvb 36

AndroidManifest.xml添加android:exported="true"

<manifest ...>
  <application ...>
    <activity
        android:exported="true"
Run Code Online (Sandbox Code Playgroud)

  • 这通过在 app/src/main/AndroidManifest.xml 中放置 `android:exported="true"` 解决了我在 flutter 中构建时的问题 (5认同)

小智 14

在 Android 11 及更低版本中,在 AndroidManifest 中声明 Activity、Service 或 Broadcast 接收器时,您没有显式声明 android:exported。由于默认值为exported=true,因此当您不想向外界透露时,只需声明exported=false即可。

<activity android:name="com.example.app.backgroundService">
    <intent-filter>
        <action android:name="com.example.app.START_BACKGROUND" />
    </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

Android 12 更改:在 Android 12 设备上将 SDK API 31 (android 12) 设置为 Target sdk 的导出应用程序的显式声明必须在声明了意图过滤器的 Activity 等组件中显式声明导出。否则会出现如下错误,安装失败。

Targeting S+ (version 10000 and above) requires that an explicit value for
android:exported be defined when intent filters are present
The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
Even for apps targeting SDK API 31, components without intent-filter can omit the exported declaration.
Run Code Online (Sandbox Code Playgroud)

您必须明确声明导出,如下所示:

Targeting S+ (version 10000 and above) requires that an explicit value for
android:exported be defined when intent filters are present
The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
Even for apps targeting SDK API 31, components without intent-filter can omit the exported declaration.
Run Code Online (Sandbox Code Playgroud)

Intent-filter 是将应用程序组件暴露给外部的方法之一。这是因为我的应用程序的组件可以通过隐式意图的解析来执行。

另一方面,在很多情况下,它仅用于在我的应用程序内部执行具有隐式意图的组件,但由于未设置导出而暴露在外部,这可能会影响问题的解析隐含的意图。。


And*_*rii 9

谢谢@rahul-kavati。

对于 Xamarin/MAUI 它是 的一个属性ActivityAttribute,像这样使用[Activity(Label = "MsalActivity", Exported = true)]