2010-12-11 9 views
7

sto cercando di andare alle impostazioni dello schermo trova a -partendo da un'attività preferences.xml

android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS 

Da una voce nella mia attività di preferenze, ma sto avendo senza fortuna. Al momento, premendo la voce si aggiorna la stessa schermata di quando ero su.

mio preferences.xml si presenta così:

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

E il mio ingresso manifesta assomiglia a questo:

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

Che cosa sto facendo di sbagliato?

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) 

manifesto:

<?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 ( dispiace per la mancanza di formattazione):

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

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

+0

Cosa dice il logcat? Inoltre, puoi pubblicare la voce manifest per la tua pagina delle preferenze principali? Quello a cui continui a tornare? – EboMike

+0

Questa è la voce manifest della mia pagina delle preferenze principali, il logcat: – qubz

+0

12-11 15: 53: 34.170: INFO/ActivityManager (173): Attività iniziale: Intent {act = android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS cmp = com. my.app/.Preferences} 12-11 15: 53: 34.400: INFO/ActivityManager (173): Attività visualizzata com.my.app/.Preferences: 229 ms (totale 229 ms) – qubz

risposta

10

Va bene, credo di capire - si può essere chiare su ciò che un intent-filtro.

vostra entrata manifesta dice:

<activity android:name=".Preferences"> 

Questa è la definizione per la vostra attività denominata [pacchetto] .Preferences.

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

Preferenze verrà attivato ogni volta che qualcuno inizia un'intenti con ACTION_LOCATION_SOURCE_SETTINGS come il nome dell'azione ...

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

questo dovrebbe essere l'opzione di default per quell'azione.

</intent-filter> 
</activity> 

Ovviamente, non si desidera utilizzare un nome dell'azione API Android per la vostra attività (a meno che non si sta cercando di fornire un'alternativa a Android built-in attività della sorgente posizione). Usa un nome di azione diverso per la schermata delle preferenze principali, preferibilmente con il nome del tuo pacchetto.

EDIT: Inoltre, provare a utilizzare un PREFERENCE:

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

Suona bene, hai ragione, non ero chiaro riguardo ai filtri di intent grazie. Farò un tentativo e vedere come va – qubz

+0

Buona fortuna! Fammi sapere come funziona! – EboMike

+0

Non sto ancora avendo fortuna perché sento che non so davvero cosa sto facendo. Stai dicendo che cambio il nome dell'azione nel manifest e nel file preferences.xml? Se lo faccio, come avvierò l'attività di origine della posizione desiderata? – qubz

1

Nulla funziona per me, così ho fatto: (Penso che sia una cattiva idea, ma ...)

1.Rimuovere questo filtro da manifesti

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

1. Fare preferenza facile

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

2. Aggiungere clickListener nel 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. Scusa il mio inglese

+0

Non so perché, ma con l'altro metodo invece dell'attività che dichiaro, ha aperto di nuovo l'attività delle preferenze, quindi questo metodo ha funzionato per me (: – FeanDoe

Problemi correlati