19

からシステムの位置情報設定を起動したいIntent。プログラム的にはこのようになることを私は知っています

Intent viewIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(viewIntent);

しかし、a の XML から行う必要がありますPreference。私はこのようにしてみます

<Preference
    android:title="@string/pref_title" >
    <intent android:action="android.settings.ACTION_LOCATION_SOURCE_SETTINGS" />
</Preference>

しかし、うまくいきませんActivityNotFoundException。XML インテントからそのシステムの場所の設定を起動するにはどうすればよいですか?

4

2 に答える 2

41

設定を表すa:PreferenceActivityを作成し、次のように を設定に割り当てることができonClickます。

Preference goToLocationSettings = (Preference) findPreference("goToLocationSettings");
goToLocationSettings.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            Intent viewIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(viewIntent);

            return true;
        }
    });

また、xml ファイルで設定にキーを割り当てる必要があります。

<Preference
    android:key="goToLocationSettings"
    android:title="@string/pref_title" />
于 2013-04-14T16:48:44.950 に答える
0

このコードを試してください:

<PreferenceScreen
    android:key="key_location"
    android:summary="location settings"
    android:title="Open location settings">

    <intent android:action="android.settings.ACTION_LOCATION_SOURCE_SETTINGS"/>

</PreferenceScreen>
于 2016-01-13T23:16:29.913 に答える