我正在尝试转到位于的设置屏幕-

android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS

从我的喜好 Activity 中的一个条目开始,但是没有运气。此刻,按条目将刷新与我所在的屏幕相同的屏幕。

我的preferences.xml看起来像这样:
<Preference
         android:title="@string/my_location_settings">
    <intent android:action="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS">
    </intent>
 </Preference>

我的 list 条目看起来像这样:
<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>

我究竟做错了什么?

日志猫:
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)

显现:
<?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(
对缺少格式表示抱歉):
  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);
    }
}

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

最佳答案

好的,我想我理解-您可能不清楚什么是意图过滤器。

您的 list 条目说:

<activity android:name=".Preferences">

这是您的 Activity 的定义,名称为[your package] .Preferences。
 <intent-filter>
    <action android:name="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS" />

每当有人以ACTION_LOCATION_SOURCE_SETTINGS作为 Action 名称启动意图时,都会触发偏好设置...
        <category android:name="android.intent.category.DEFAULT" />

这应该是该操作的默认选项。
    </intent-filter>
</activity>

显然,您不想为 Activity 使用Android API Action 名称(除非您尝试提供Android内置的位置来源 Activity 的替代方法)。在您的主要偏好设置屏幕上使用其他操作名称,最好是其中包含您的包裹名称的名称。

编辑:另外,请尝试使用PreferenceScreen:
<PreferenceScreen android:title="@string/my_location_settings">
    <intent android:action="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS">
    </intent>
</PreferenceScreen>

09-10 06:15
查看更多