Question

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!

Was it helpful?

Solution

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>

OTHER TIPS

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>

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à!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top