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!
Asked by: Edgar791 | Posted: 25-01-2022
Answer 1
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>
Answered by: Lucas331 | Posted: 26-02-2022
Answer 2
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>
Answered by: Aida234 | Posted: 26-02-2022
Answer 3
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à!
Similar questions
android - After changing a preference (a setting), text showing settings doesn't update
I will try to explain a simple app scenario: My app goes right to a 'main view'. In this main view I have inserted a TextView which displays current settings created by way of the PreferenceManager. For simplicity sake, let's say I have a checkbox in my settings. When I first start my app - the TextView on my main view shows my checkbox setting correctly (true). Now I go to the settin...
android - Intent receiver according to preference
I have a intent receiver in my android manifest, but would like to give the user the opportunity to choose whether he/her wants the app to automatically start at the specific state. Until now, I've used a service with a broadcast receiver, but I really want to delete this service as it seems a bit unnecessary.
Can register the intent action only if the user wants it (I guess not)? If not, should I make a class that...
android - Preference screen xml
I have a main view that presents to the user the settings he/she can modify for an application . It's xml is something like this :
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="root_preferencescreen">
<PreferenceScreen android:key="general_sett" android:title="general settings" />
....
<PreferenceScreen android:key="ex...
android - Custom preference screen
I have a slider for the user to control the volume of my application. What I'd like to have is a icon or something else similar to "volume display" like in the next picture at the slider summary. Is this possible ? How could this be accomplished ?
android - Nested preference screens lose theming
I have a preference screen for my application and in the manifest I have given it a theme using:
android:theme="@android:style/Theme.Light.WallpaperSettings"
However when I nest another preference screen inside this one such as:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@st...
Android preference, does it have to be unique?
For my private static final String PREFS_NAME = "mypref"; does the PREFS_NAME have to be unique for every application? Or can I use the same one over and over.
java - Where to store Android preference keys?
When I create preference activity I define all preferences in xml file. Every preference has a key defined in this xml. But when I access preference I write:
SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean foo_value = appPreferences.getBoolean("foo_key_defined_in_xml", false);
Is there any way to avoid referencing "foo_key_defined_in_xml" in...
android - How do I get a preference to correlate to a variable?
I have my menu button bringing up a Settings option, which brings up numerous ListPreferences such as weight and various sizes for glasses (it's a BAC calculator app). I'll pick one example... weight will work.
Depending on how much you weigh it will affect your BAC. I have a int for Weight, set at 180. I would like someone to be able to go into the menu Settings, pick the "Weight" ListPreference, and choose betwee...
Android ==> Preference?
my app crashes with a null pointer exception on the code below.
i have an xml preference file under res/xml/defaults.xml
Any idea why it's crashing?
public class Preference extends Activity {
public Preference()
{
}
public String getPreference(String key)
{
//it still crashes here
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this...
android - Failed to start my preference activity
Currently I am trying to add a preference activity into my application
but found out that I couldn't make it works.
Every time, I tried to start the preference activity but it just crash before showing anything.
Here is the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="keysquare.android"
android:vers...
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android