Iniciar una actividad desde preferences.xml

Estoy tratando de ir a la pantalla de configuración que se encuentra en –

android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS 

De una entrada en mi actividad de las preferencias pero estoy teniendo ninguna suerte. En este momento, al presionar la entrada sólo se actualiza la misma pantalla que estaba encendida.

Mis preferencias.xml tiene este aspecto:

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

Y mi entrada de manifiesto se parece a esto:

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

¿Qué estoy haciendo mal?

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) 

Manifiesto:

 <?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 (lo siento por la falta de formato):

  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); } } 

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

Bueno, creo que entiendo – puede ser poco claro acerca de lo que es un filtro de intención.

Su entrada de manifiesto dice:

 <activity android:name=".Preferences"> 

Esta es la definición de su actividad llamada [your package] .Preferences.

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

Las preferencias se activarán cuando alguien inicie una intención con ACTION_LOCATION_SOURCE_SETTINGS como el nombre de la acción …

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

Se supone que esta es la opción predeterminada para esa acción.

  </intent-filter> </activity> 

Obviamente, no desea utilizar un nombre de acción de la API de Android para su actividad (a menos que intente proporcionar una alternativa a la actividad de origen de la ubicación integrada de Android). Utilice un nombre de acción diferente para la pantalla de preferencias principales, preferiblemente algo con su nombre de paquete.

EDIT: También, intente usar una PreferenceScreen:

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

Nada funciona para mí, así que lo hice: (Creo que es una mala idea, pero …)

1.Remove este filtro de manifiesto

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

1. Haga la preferencia más fácil

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

2. Agregue Clicklistener en su 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; } }); } 

PS Lo siento por mi inglés

  • ¿El color predeterminado de las preferencias de Android?
  • Atributo de visibilidad en las preferencias xml no funciona? (Android 2.3)
  • Android: ¿Cómo puede hacer PreferenceScreen personalizado?
  • Android PreferenceScreen Barra de título quitar
  • ¿Cómo validar el formato y los valores de EditTextPreference introducidos en Android 2.1?
  • No se puede guardar ni cargar entero con las preferencias
  • Procesar el valor de preferencia antes de guardar en Android?
  • Preferencias de Android: Valores predeterminados incorrectos DESPITE "setDefaultValues"
  • Android: Recuperación de preferencias compartidas de otra aplicación
  • Uso de un tema para la pantalla de preferencias
  • ¿Cómo agregar la categoría en el encabezado de preferencia?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.