起价preferences.xml活动起价、preferences、xml

2023-09-12 04:59:52 作者:理想七旬

我试图去发现,在设置画面 -

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

android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS

这是在我的preferences活动的项目,但我有没有运气。目前,pressing项只是刷新了同一个屏幕,我开始了。

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.

我的preferences.xml看起来是这样的:

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)

清单:

<?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( 遗憾的是,没有格式化的):

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

和preferences.xml:

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>

推荐答案

好吧,我想我明白 - 你可能不清楚意向过滤器是什么

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

您的清单条目说:

<activity android:name=".Preferences">

这是要求你的活动的定义[你的包。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每当有人开始意图与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>

显然,你不希望使用Android的API操作名称为您的活动(除非你想提供替代Android的内置定位服务活动)。你的主preferences屏幕,preferably东西在里面你的包名使用不同的动作的名称。

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.

编辑:另外,请尝试使用preferenceScreen:

Also, try using a PreferenceScreen:

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