2010-01-16 43 views
7

我在這裏遇到了一些問題。我想要做的是從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> 

你猜怎麼着,我得到一個安全例外(權限拒絕),當我想啓動它。我錯過了什麼嗎?我對意圖的理解還有點不完整,但我認爲必須這樣工作。

謝謝你的幫助!

+0

你可以發佈堆棧跟蹤嗎? – 2010-01-16 14:47:48

+0

對不起,自己弄明白了。該死的日食切割的錯誤信息,該死的自我沒有注意到它。感謝您無論如何看看它! – moritz 2010-01-16 17:47:42

+6

如果你已經想出瞭解決方案,可以將解決方案作爲答案發布。有人遇到同樣的問題可能最終會通過谷歌,所以如果我們也可以在頁面上找到解決方案,那將是非常好的。 – 2010-01-16 18:43:40

回答

20

製作一個意圖過濾器看起來像是一個稍微迂迴的做法。這是一個簡單的方法:

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

這應該被接受的答案。適用於所有Android版本。 – tomrozb 2014-10-14 09:03:02

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> 
0

我我的情況下我所有的XML設置是正確的。

但我發起活動(名爲AppPreferences)由於惡劣refractoring存在於的地方:[package].AppPreferences和[[package].commmon.Preferences 因爲一個import common._,有人以此爲活動,當然它在Android清單未聲明。 我只是不得不從我的代碼中刪除第二個活動,瞧!

相關問題