Android 14 之 隐式Inten增加限制

578 阅读1分钟

Android 14中,为了防止恶意应用程序拦截旨在供应用程序内部组件使用的隐式intent,

对隐式Intent做了两点限制:

  1. 隐式Intent不声明PackageName会抛出异常

  2. 隐式Intent可以对 android:exported="true"的组件使用

  • 先看下官网给出的示例
  <activity
        android:name=".AppActivity"
        //exported 为false,说明不对外提供
        android:exported="false">
        <intent-filter>
            <action android:name="com.example.action.Second_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
  • 使用隐式Intent来调用此Activity
context.startActivity(Intent("com.example.action.Second_ACTION"))

val explicitIntent = Intent("com.example.action.Second_ACTION")
explicitIntent. ` package ` ="com.cao.myapplication"
this.startActivity(explicitIntent)