Android中Activity的export属性

android中activity的exported的属性


作者:燕潇洒
导读:在使用adb命令打开android应用程序时,出现了安全异常,因为这个异常又了解到了有意思的东西!


问题
在cmd窗口使用adb命令打开app的某个页面时,出现了安全异常,异常如下:

Starting: Intent { cmp=com.telehot.ecard/.ui.activity.CaptureActivity }
java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000
cmp=com.telehot.ecard/.ui.activity.CaptureActivity } from null (pid=4812, uid=2
000) not exported from uid 10236
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:2833)
at com.android.commands.am.Am.runStart(Am.java:875)
at com.android.commands.am.Am.onRun(Am.java:359)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.am.Am.main(Am.java:100)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:357)

网上搜索这个问题,在IT屋的网站中看到了android:export这个属性:

android:exported
Whether or not the activity can be launched by components of other applications — "true" if it can be, and "false" if not. If "false", the activity can be launched only by components of the same application or applications with the same user ID.

The default value depends on whether the activity contains intent filters. The absence of any filters means that the activity can be invoked only by specifying its exact class name. This implies that the activity is intended only for application-internal use (since others would not know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the activity is intended for external use, so the default value is "true".

This attribute is not the only way to limit an activity's exposure to other applications. You can also use a permission to limit the external entities that can invoke the activity (see the permission attribute).

中文解释:

安卓:出口
活动是否可以由其他应用程序的组件启动:“true”,如果可以的话;
也可以是"false",如果不可以。
如果"false",活动只能由具有相同用户ID的相同应用程序或应用程序的组件启动。

默认值取决于活动是否包含意图过滤器。没有任何筛选器意味着只能通过指定其确切类名来调用该活动。这意味着该活动仅用于应用程序内部使用(因为其他人不知道类名)。因此,在这种情况下,默认值是“false”。另一方面,至少有一个过滤器的存在意味着该活动是为外部使用,所以默认值是“true”。

此属性并不是限制活动暴露于其他应用程序的唯一方法。您还可以使用权限来限制可以调用该活动的外部实体(请参阅权限属性)。

解决

知道了原因,我们打开应用程序在要打开的activity添加属性:

android:exported="true"

然后在次调用adb命令,如下:

adb shell am start -n {包名}/{包名.类名}

打开cmd,输入命令

adb shell am start -n com.telehot.quan/com.telehot.quan.ui.activity.company.BusinessMainActivity

回车,正常打开页面。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值