Android 通过preferences.xml中的Intent打开应用程序设置
我想通过单击首选项打开应用程序设置。因此,我在preferences.xml中添加了一个意图Android 通过preferences.xml中的Intent打开应用程序设置,android,xml,android-intent,preferences,Android,Xml,Android Intent,Preferences,我想通过单击首选项打开应用程序设置。因此,我在preferences.xml中添加了一个意图 <PreferenceScreen android:key="DELETE_DATA" android:title="@string/pref_delete_data"> <intent android:action="android.provider.Settings.ACTION_APPLICATION_DETAILS_SET
<PreferenceScreen
android:key="DELETE_DATA"
android:title="@string/pref_delete_data">
<intent android:action="android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS"/>
</PreferenceScreen>
我在AndroidManifest.xml中添加了一个意图过滤器
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".MainActivity">
<intent-filter>
<action android:name="android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
...
...
使用上面的代码,没有任何操作或错误。但我不知道为什么。。。
如果我要删除
,则会出现错误,因此会触发意图。有什么想法吗
设备:HTC One M8和安卓4.4.4供其他对OP如何使用OnPreferenceClickListener感兴趣的人使用。但是,为了直接从意图出发开展活动,这对我来说很有效:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/pref_title_category_name">
<PreferenceScreen
android:title="@string/pref_title_activity_name"
android:key="pref_launch_settings">
<intent
android:action="android.intent.action.VIEW"
android:data="<data>"
android:targetPackage="<package name>"
android:targetClass="<target class>" />
</PreferenceScreen>
</PreferenceCategory>
数据=完整程序包名称加上活动名称。例如,com.example.myapp.ActivityName
包名=清单文件根目录中定义的包名。例如,com.example.myapp
targetClass=再次显示完整的包路径,即com.example.myapp.ActivityName
请注意,我在首选项屏幕中以这种方式使用
标记,而不是在首选项类别中使用
希望有帮助
<Preference android:title="@string/pref_app_version"
android:summary="@string/pref_app_version_summary">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="YOUR APPLICATION ID"
android:targetClass="com.my.java.packagename.MyActivity"/>
</Preference>
就是我今天注意到的。如果您使用的是不同的产品风格,请确保targetpackage是build.gradle中定义的应用程序ID。将android:data设置为您的软件包名称。将com.myapp(以下)替换为在清单文件中找到的应用程序包名称的名称
<PreferenceScreen
android:title="@string/system_settings_preference_title" >
<intent android:action="android.settings.APPLICATION_DETAILS_SETTINGS"
android:data="package:com.myapp"/>
</PreferenceScreen>
您必须在“首选项”屏幕中有一个按钮或其他东西,才能正确设置应用程序设置??嗯,PreferenceScreen
是一个嵌入式元素(因此这就是按钮)。如果我通过OnPreferenceClickListener通过代码激发意图,它就会起作用。但我更愿意通过preferences.xml
实现这一点。有什么提示吗?这很有效。不知道为什么没有投票。我还没有找到更好的答案。我想指出,如果您使用的是product Flavors,“package name”应该是应用程序Id。是否可以使用此xml声明完成调用活动?是否可以自动为applicationId生成每个flavor字符串属性: