Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Activity from Preference Activity causes Permission Denial Exception

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!

like image 388
moritz Avatar asked Jan 16 '10 13:01

moritz


2 Answers

Making an intent-filter seems like a slightly roundabout way of doing this. This is a simpler approach:

<PreferenceScreen
    android:title="@string/settings.title" 
    android:summary="@string/settings.summary">
    <intent
        android:targetPackage="com.companyname.appname"
        android:targetClass="com.companyname.appname.classname"/>
</PreferenceScreen>
like image 175
haemish Avatar answered Jan 06 '23 15:01

haemish


Fully work example In your 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>

In your 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>
like image 32
Blackbern Avatar answered Jan 06 '23 15:01

Blackbern