1
  • 我通过代码创建了一些我的活动的快捷方式,其中大多数都无法打开其相关活动。我发现它只有在我将过滤器 CREATE_SHORTCUT 添加到活动时才有效。为什么?

       <activity
           android:name=".ui.Main"
           android:launchMode="singleTop"
           android:screenOrientation="portrait"
           android:theme="@android:style/Theme.NoTitleBar" >
           <intent-filter>
               <action android:name="android.intent.action.CREATE_SHORTCUT" />
               <category android:name="android.intent.category.DEFAULT" />
           </intent-filter>
       </activity>
    

    (在 Go Launcher 和 MIUI 2.3.7 中测试)

  • 我得到了下面的日志,我应该添加 MAIN 过滤器吗?

    09-27 13:34:44.075: E/Launcher(7893): Launcher 没有
    权限启动 Intent { act=android.intent.action.VIEW
    flg=0x10000000 cmp=/.ui.Activity2 bnds=[349, 76][469,211]}。确保为相应的活动创建一个主意图过滤器或为此活动使用导出的属性。

4

1 回答 1

6

正如错误消息所示,您可以添加

android:exported="true"

到你的活动。

尽管如果我正确阅读了android文档,这应该是默认值:

安卓:导出

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".

Maybe someone else can clarify this.

于 2012-09-27T08:20:09.410 回答