【问题标题】:Launch Activity from Preference Activity causes Permission Denial Exception从 Preference Activity 启动 Activity 导致 Permission Denial 异常
【发布时间】:2010-01-16 13:21:55
【问题描述】:

我在这里遇到了一些问题。我想要做的是从 PreferenceActivity 中启动一个 Activity。所以我的preference.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>

你猜怎么着,当我想启动它时,我得到了一个安全异常( Permission Denial )。我错过了什么吗?我对意图的理解仍然有点不完整,但我认为它必须以这种方式工作。

感谢您的帮助!

【问题讨论】:

  • 你能发布堆栈跟踪吗?
  • 对不起,我自己想通了。该死的日食切割错误消息,该死的自己没有注意到它。无论如何,谢谢你看看它!
  • 如果你想通了,你可以发布解决方案作为答案。与您遇到相同问题的人可能最终会通过 Google 来到这里,所以如果我们也能在页面上找到解决方案,那就太好了。
  • 您错过了活动名称前的点。

标签: android android-activity preference


【解决方案1】:

制作意图过滤器似乎是一种稍微迂回的方式。这是一种更简单的方法:

<PreferenceScreen
    android:title="@string/settings.title" 
    android:summary="@string/settings.summary">
    <intent
        android:targetPackage="com.companyname.appname"
        android:targetClass="com.companyname.appname.classname"/>
</PreferenceScreen>

【讨论】:

  • 这应该是被接受的答案。适用于所有 Android 版本。
【解决方案2】:

完整的工作示例 在你的preference.xml中

<Preference 
        android:title="@string/settings_title_notification_silent_mode"
        android:summary="@string/settings_title_notification_silent_mode_summary">
  <intent
   android:action="com.activity.SilentModeList"/> <!-- SilentModeList its activity -->
  </Preference>

在你的 manifest.xml 中

      <activity android:name="com.activity.SilentModeList"
            android:label="@string/ac_settings_description">
           <intent-filter>
               <action android:name="com.activity.SilentModeList" />
               <category android:name="android.intent.category.DEFAULT" />
           </intent-filter>
      </activity>

【讨论】:

    【解决方案3】:

    我的情况是我的所有 xml 设置都是正确的。

    但我发起的活动(名为AppPreferences)由于折射不良存在于以下地方:[package].AppPreferences和[[package].commmon.Preferences 因为import common._,它把它当作活动,当然它没有在Android清单中声明。 我只需要从我的代码中删除第二个活动,瞧!

    【讨论】:

      猜你喜欢
      • 2012-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多