我正在尝试进入设置屏幕,位置是-
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS来自我的preferences活动中的一个条目,但我没有运气。此时,按下该条目只会刷新与我打开时相同的屏幕。
我的preferences.xml看起来像这样:
<Preference
android:title="@string/my_location_settings">
<intent android:action="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS">
</intent>
</Preference>我的清单条目看起来像这样:
<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>我做错了什么?
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 (很抱歉没有设置格式):
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>
发布于 2010-12-11 13:13:02
好的,我想我明白了--你可能不清楚什么是意图过滤器。
您的清单条目显示:
<activity android:name=".Preferences">这是您的活动的定义,称为package.Preferences。
<intent-filter>
<action android:name="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS" />每当有人以ACTION_LOCATION_SOURCE_SETTINGS作为操作名称启动一个意图时,就会触发首选项...
<category android:name="android.intent.category.DEFAULT" />这应该是该操作的默认选项。
</intent-filter>
</activity>显然,您不希望为您的活动使用Android API操作名称(除非您试图提供Android内置位置源活动的替代方案)。对于您的主首选项屏幕,请使用不同的操作名称,最好是其中包含您的包名称的名称。
编辑:另外,尝试使用PreferenceScreen:
<PreferenceScreen android:title="@string/my_location_settings">
<intent android:action="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS">
</intent>
</PreferenceScreen>发布于 2015-05-27 17:51:31
没有什么对我有效,所以我这么做了:(我认为这是个坏主意,但是……)
1.从清单中删除此过滤器
<intent-filter>
<action android:name="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>(让首选项更简单)
<Preference android:key="simple_key"
android:title="@string/title_simple_key">
</Preference>在您的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;
}
});
}附言:对不起,我的英语
https://stackoverflow.com/questions/4415241
复制相似问题