您的位置:首页 > 教育 > 培训 > Android 14 适配之 - 隐式/显示 Intent 和 广播适配

Android 14 适配之 - 隐式/显示 Intent 和 广播适配

2024/10/6 12:27:14 来源:https://blog.csdn.net/qq_27247815/article/details/140557210  浏览:    关键词:Android 14 适配之 - 隐式/显示 Intent 和 广播适配

隐式 Intent

对隐式Intent 限制:

对 Android 14(API 级别 34)或更高版本为目标平台的应用,Android 会限制应用向内部应用组件发送隐式 intent:

1. 即隐式 intent 只能发送给导出的组件。在应用必须使用显式 intent 来发送组件,且被发送的组件是未被导出的属性配置。

2. 如果被发出的组件是先导出的配置,则可以使用隐式的Intent。

此变更是为防止恶意应用拦截意在供应用内部组件使用的隐式 intent。

如下示例:

<activity
    android:name=".AppActivity"
    android:exported="false">
    <intent-filter>
        <action android:name="com.example.action.APP_ACTION" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

若尝试使用隐式 intent 启动此 activity,则系统会抛出异常;比如如下方式启动,则会抛出异常:

Kotlin 版本: // Throws an exception when targeting Android 14. context.startActivity(Intent("com.example.action.APP_ACTION"))

java 版本 

// Throws an exception wh

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com