gpt4 book ai didi

android - 通过 preferences.xml 中的 Intent 打开应用程序设置

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:41 25 4
gpt4 key购买 nike

我想通过单击首选项条目来打开应用程序设置。所以我在 preferences.xml 中添加了一个 Intent

    <PreferenceScreen
android:key="DELETE_DATA"
android:title="@string/pref_delete_data">
<intent android:action="android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS"/>
</PreferenceScreen>

并且我在 AndroidManifest.xml 中添加了一个 Intent-filter

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

使用上面的代码,没有任何 Action 或错误。但我不知道为什么...如果我要删除 <category>出现错误,因此触发了 Intent 。有什么想法吗?

设备:搭载 Android 4.4.4 的 HTC One M8

最佳答案

对于其他对 OP 如何使用 OnPreferenceClickListener 感兴趣的人,check out this answer from a similar question .但是要直接从 Intent 启动 Activity ,这对我有用:

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

数据 = 完整包名称加上 Activity 名称。即 com.example.myapp.ActivityName

包名称 = list 文件根目录中定义的包名称。即 com.example.myapp

targetClass = 完整包路径,即 com.example.myapp.ActivityName

请注意,我使用的是 <intent>PreferenceScreen 中以这种方式标记, 而不是 PreferenceCategory .

希望对您有所帮助!

关于android - 通过 preferences.xml 中的 Intent 打开应用程序设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28154832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com