Reputation: 2197
I created some shortcut of my activities by code, most of them can't open its related activity. I found that it only work if I added filter CREATE_SHORTCUT to activity. Why?
<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>
(test in Go Launcher & MIUI 2.3.7)
I got logs below, should I add MAIN filter?
09-27 13:34:44.075: E/Launcher(7893): Launcher does not have the
permission to launch Intent { act=android.intent.action.VIEW
flg=0x10000000 cmp=/.ui.Activity2 bnds=[349,76][469,211] }. Make
sure to create a MAIN intent-filter for the corresponding activity
or use the exported attribute for this activity.
Upvotes: 1
Views: 2555
Reputation: 30025
As the error message suggests, you could add
android:exported="true"
to your activity.
Although this should be the default value if I read the android documentation right:
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".
Maybe someone else can clarify this.
Upvotes: 6