7

I'm trying to go to the settings screen found at -

android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS

From an entry in my preferences activity but am having no luck. At the moment, pressing the entry just refreshes the same screen as I was on.

My preferences.xml looks like this:

<Preference
         android:title="@string/my_location_settings">
    <intent android:action="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS">
    </intent>
 </Preference>

And my manifest entry looks like this:

<activity android:name=".Preferences">
        <intent-filter>
            <action android:name="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

What am I doing wrong?

logcat:

12-11 15:53:34.170: INFO/ActivityManager(173): Starting activity: Intent { act=android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS cmp=com.my.app/.Preferences }
12-11 15:53:34.400: INFO/ActivityManager(173): Displayed activity com.my.app/.Preferences: 229 ms (total 229 ms)

Manifest:

<?xml version="1.0" encoding="utf-8"?>

    <activity android:name=".ViewActivity" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MyPageOneActivity">
    </activity>
    <activity android:name=".MyPageTwoActivity">
    </activity>
    <activity android:name=".MyPageThreeActivity">
    </activity>
    <activity android:name=".Preferences">
        <intent-filter>
            <action android:name="com.my.app.PREFERENCES" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
</uses-permission>
</manifest>

Preferences.java ( sorry about the lack of formatting):

  package com.my.app;

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class Preferences extends PreferenceActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.preferences);
    }
}

and preferences.xml:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference 
    android:title="Address 1"
    android:key="customURLOne" 
    android:summary="Enter a new address for 1">
</EditTextPreference>
<EditTextPreference 
    android:title="Address 2"
    android:key="customURLTwo" 
    android:summary="Enter a new address for 2">
</EditTextPreference>
<EditTextPreference 
    android:title="Address 3"
    android:key="customURLThree" 
    android:summary="Enter a new address for 3">
</EditTextPreference>
 <Preference android:title="@string/my_location_settings">
    <intent android:action="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS">
    </intent>
 </Preference>

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
qubz
  • 760
  • 3
  • 11
  • 20
  • What does the logcat say? Also, can you post the manifest entry for your main preferences page? The one that you keep getting back to? – EboMike Dec 11 '10 at 04:47
  • That is the manifest entry for my main preferences page, the logcat: – qubz Dec 11 '10 at 04:53
  • 12-11 15:53:34.170: INFO/ActivityManager(173): Starting activity: Intent { act=android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS cmp=com.my.app/.Preferences } 12-11 15:53:34.400: INFO/ActivityManager(173): Displayed activity com.my.app/.Preferences: 229 ms (total 229 ms) – qubz Dec 11 '10 at 04:54
  • I still don't see the manifest entry for the main page, only for the one you're trying to get to. – EboMike Dec 11 '10 at 05:06
  • oh sorry, the one Im trying to get to is part of the android os, I also get to it using an alert box by using the statements: Intent myLocationOptionsIntent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(myLocationOptionsIntent); This brings up the Locations & Security settings under the Android Settings list – qubz Dec 11 '10 at 05:08
  • I don't understand. Your preferences intent is saying ACTION_LOCATION_SOURCE_SETTINGS, so clearly you're trying to launch the activity ".Preferences". – EboMike Dec 11 '10 at 05:08
  • Right, I think I'm getting confused. I want to bring up the settings list for Locations & security, the same one brought up by the code in the comment just above. The .Preferences activity launches fine, then I want to go to the Locations and Security settings from an entry in the list. This is where it returns to the same screen. – qubz Dec 11 '10 at 05:11

2 Answers2

11

Okay, I think I understand - you may be unclear about what an intent-filter is.

Your manifest entry says:

<activity android:name=".Preferences">

This is the definition for your activity called [your package].Preferences.

 <intent-filter>
    <action android:name="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS" />

Preferences will be triggered whenever somebody starts an intent with ACTION_LOCATION_SOURCE_SETTINGS as the action name...

        <category android:name="android.intent.category.DEFAULT" />

This is supposed to be the default option for that action.

    </intent-filter>
</activity>

Obviously, you don't want to use an Android API action name for your activity (unless you're trying to provide an alternative to Android's built-in location source activity). Use a different action name for your main preferences screen, preferably something with your package name in it.

EDIT: Also, try using a PreferenceScreen:

<PreferenceScreen android:title="@string/my_location_settings">
    <intent android:action="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS">
    </intent>
</PreferenceScreen>
EboMike
  • 76,846
  • 14
  • 164
  • 167
  • Sounds good, your right, I was unclear about intent filters thank you. I'll give it a shot and see how it goes – qubz Dec 11 '10 at 05:17
  • I'm still not having any luck cause I feel I don't really know what I am doing. Are you saying I change the action name in the manifest and the preferences.xml file? If I do that, how will I start the desired location source activity? – qubz Dec 11 '10 at 05:47
  • No. Change the action name of your ".Preferences" activity. Keep everything else the same. If you still have problems, post the entire manifest file. – EboMike Dec 11 '10 at 05:48
  • No love, I changed the action name in the manifest to - but no joy. Ill post the whole manifest and Preferences activity and preferences.xml in the OP – qubz Dec 11 '10 at 06:08
  • Ah, one more thing - your preference item needs to be a PreferenceScreen. I'll edit my answer. – EboMike Dec 11 '10 at 06:51
  • Thanks you. I have to go now and will pick this up when I get back, thanks again. – qubz Dec 11 '10 at 06:59
  • I'm now getting: 12-11 20:25:41.294: ERROR/AndroidRuntime(7458): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS } when implementing your instructions. – qubz Dec 11 '10 at 09:29
  • We're getting there. android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS is a static String in the Android API, and it is "android.settings.LOCATION_SOURCE_SETTINGS". Use that string instead. – EboMike Dec 11 '10 at 10:13
  • So sweet!, it worked!! This is great, thank you so much EboMike There is no way I'd have known it was that string. Problem solved :) – qubz Dec 11 '10 at 10:49
3

Nothing works for me so i did: (I think it is a bad idea but...)

1.Remove this filter from manifest

<intent-filter>
<action android:name="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

1. Make preference easier

<Preference android:key="simple_key"
        android:title="@string/title_simple_key">
    </Preference>

2. Add Clicklistener in your PreferenceFragment

  @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.layout.preferences);
    // Load the preferences from an XML resource
    findPreference("simple_key").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            startActivity(new Intent(
                    android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
            return false;
        }
    });

}

P.S. Sorry for my English

  • I don't know why, but with the other method instead of the activity that I declare, it opened the preferences activity again, so this method worked for me (: – FeanDoe Jun 21 '17 at 18:35