当前位置:   article > 正文

android:exported=“false“_android:exported="false

android:exported="false

书籍:

《第一行代码 Android》第三版

开发环境:

Android Studio Jellyfish | 2023.3.1

问题:

A launchable activity must be exported as of Android 12, which also makes it available to other apps

新建的activity中的android:exported="false",如下图所示:

  1. <activity
  2. android:name=".FirstActivity"
  3. android:exported="false"
  4. </activity>

为程序配置主Activity,代码如下所示:

  1. <activity
  2. android:name=".FirstActivity"
  3. android:exported="false"
  4. android:label="This is FirstActivity" >
  5. <intent-filter>
  6. <action android:name="android.intent.action.MAIN" />
  7. <category android:name="android.intent.category.LAUNCHER" />
  8. </intent-filter>
  9. </activity>

此时会出现一个问题:A launchable activity must be exported as of Android 12, which also makes it available to other apps.

解决方法:

将android:exported="false"设置为android:exported="true"。

原因如下:

(原文链接:Android:exported 属性知识-CSDN博客

1、android:exported 是 Android中的四大组件 Activity,Service,Provider,Receiver 四大组件中都会有的一个属性。
2、android:exported 代表是否能被其他应用隐式调用。
3、true允许被启动,false不允许被启动。
4、android:exported 默认值是由有无intent-filter决定的,如果有intent-filter,默认值为true,否则为false。
5、android:exported = false的情况下,这个Activity将只会被当前Application或者拥有同样user ID的Application的组件调用,对于其他应用,即使有intent-filter匹配,也无法打开,即无法被其他应用隐式调用。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/900647
推荐阅读
相关标签
  

闽ICP备14008679号