简体   繁体   English

如何在Android中实现下载位置的首选项活动

[英]How to implement a preference activity for download location in android

I have developed an app which downloads some files from server. 我开发了一个应用程序,可以从服务器下载一些文件。 I'm using android download manager to download files to mobile device. 我正在使用android下载管理器将文件下载到移动设备。 I want to build a settings screen asking default location to store files using preference activity. 我想建立一个设置屏幕,询问默认位置以使用首选项活动存储文件。 How can i implement it. 我该如何实施。

I want to show all the storage options available in mobile in preference activity. 我想在首选项活动中显示移动设备中所有可用的存储选项。 Currently i'm using below line to store the files using download manage. 目前,我正在使用以下行通过下载管理来存储文件。

Here is the code: 这是代码:

request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS + DownloadEntries.getFile_dest_path(), filepaths.get(i));

Please help. 请帮忙。 I'm new to android. 我是android新手。

What you need is something called PreferenceFragment 您需要的是称为PreferenceFragment的东西

Preference fragment is just an easy way of creating a settings screen in Android. 首选项片段只是在Android中创建设置屏幕的一种简便方法。

You can refer here for the Preference Fragments. 您可以在这里参考首选项片段。

Since Preference Fragments doesn't support file pickers by default, you can use this library here for the file picker. 由于默认情况下,“首选项片段”不支持文件选择器,因此您可以在此处将此库用于文件选择器。

So you can tell the user to pick a folder and you can create your file in there. 因此,您可以告诉用户选择一个文件夹,然后可以在其中创建文件。

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

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