从首选项活动启动活动导致权限拒绝异常
我这里有点问题。我想要做的是从 PreferenceActivity 中启动一个 Activity。所以我的偏好设置.xml 包含首选项布局,如下所示:
<Preference android:title="Launch Activity" >
<intent android:action="org.momo.SOME_ACTIVITY" />
</Preference>
清单知道我想要启动的活动。
<activity android:label="@string/app_name" android:name="SomeActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="org.momo.SOME_ACTIVITY" />
</intent-filter>
</activity>
猜猜看,当我想要启动它时,我收到了安全异常(权限拒绝)。我错过了什么吗?我对意图的理解仍然有点不完整,但我认为它必须这样工作。
感谢您的帮助!
I'm having a bit of a problem here. What I want to do is launch an Activity from within the PreferenceActivity. So my preference.xml which holds the preference layout looks like this:
<Preference android:title="Launch Activity" >
<intent android:action="org.momo.SOME_ACTIVITY" />
</Preference>
The manifest is aware of the activity I want to launch..
<activity android:label="@string/app_name" android:name="SomeActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="org.momo.SOME_ACTIVITY" />
</intent-filter>
</activity>
guess what, I'm getting a Security Exception ( Permission Denial ) when I want to launch it. Am I missing something? My understanding of intents is still a bit incomplete, yet I figured that it must work that way.
Thank you for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
制作意图过滤器似乎是一种稍微迂回的方法。这是一个更简单的方法:
Making an intent-filter seems like a slightly roundabout way of doing this. This is a simpler approach:
完全工作示例
在你的preference.xml中
在你的manifest.xml中
Fully work example
In your preference.xml
In your manifest.xml
我的情况是我的所有 xml 设置都是正确的。
但是由于存在不良折射,我启动的活动(名为
AppPreferences
)存在于以下位置:[package].AppPreferences
和[[package].commmon.Preferences< /代码>
由于
导入common._
,它将此作为活动,当然它没有在Android清单中声明。我只需从代码中删除第二个活动即可!
I my case all my xml settings were correct.
But the activity I launched (named
AppPreferences
) due to bad refractoring existed in to places:[package].AppPreferences
and[[package].commmon.Preferences
Because of an
import common._
, it was taking this as the activity and of course it was not declared in the Android manifest.I just had to delete the second activity from my code and voilà!