在使用adb命令打开android应用程序时,出现了安全异常:
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
回车,正常打开页面。