简体   繁体   English

首选Android图库专辑

[英]Android Gallery Album as a Preference

I am writing an application which needs to provide a simple preference allowing a user to select an album from their gallery that my application will then load images from. 我正在编写一个应用程序,该应用程序需要提供一个简单的首选项,允许用户从其图库中选择一个相册,然后我的应用程序将从该相册中加载图像。

What I'd like to know is what the simplest method of doing this is, is it possible to do this from a preferences XML file, ie - can I do something like: 我想知道的是最简单的方法是,可以从首选项XML文件中执行此操作,即-我可以执行以下操作吗:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen...>
    <Preference...>
        <Intent-Filter>
            <action android:name="android.intent.action.GET_CONTENT" />
            <data android:mimeType="image/*" />
        </Intent-Filter>
    </Preference>
</PreferenceScreen>

Or something similar, or is it not possible to receive (and store) a return value via this method? 还是类似的东西,还是无法通过此方法接收(存储)返回值? If this is not possible, then what is the simplest way to do this as a custom preference in code. 如果这不可能,那么最简单的方法是在代码中将此作为自定义首选项。

Please limit any answers to Android 2.2 as this is the minimum version I'm looking to support. 请限制对Android 2.2的任何回答,因为这是我希望支持的最低版本。

I'm not sure if there's a way to do it via xml, but you can always do it via code. 我不确定是否可以通过xml来实现,但是您始终可以通过代码来实现。 Provide a click listener for the preference, and have it launch the intent via startActivityForResult, then write the result to preferences when it returns. 为首选项提供一个单击侦听器,并使其通过startActivityForResult启动意图,然后在返回时将结果写入首选项。

Remember too that you can always create a custom preference. 还要记住,您始终可以创建自定义首选项。 That ability has been around forever. 这种能力永远存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM