我正在尝试为我的 Android Java 音乐播放器使用 MaterialFilePicker。我已将它包含在我的两个
build.gradle
文件中,并相应地调整了我的 colors.xml
和 styles.xml
文件,但不知道下一步该去哪里。 GitHub 存储库中的readme.md
文件告诉我:
打开你的课程并添加以下代码
并为我提供了这段代码:
...
public static final int FILE_PICKER_REQUEST_CODE = 989
...
MaterialFilePicker()
// Pass a source of context. Can be:
// .withActivity(Activity activity)
// .withFragment(Fragment fragment)
// .withSupportFragment(androidx.fragment.app.Fragment fragment)
.withActivity(this)
// With cross icon on the right side of toolbar for closing picker straight away
.withCloseMenu(true)
// Entry point path (user will start from it)
.withPath(alarmsFolder.absolutePath)
// Root path (user won't be able to come higher than it)
.withRootPath(externalStorage.absolutePath)
// Showing hidden files
.withHiddenFiles(true)
// Want to choose only jpg images
.withFilter(Pattern.compile(".*\\.(jpg|jpeg)$"))
// Don't apply filter to directories names
.withFilterDirectories(false)
.withTitle("Sample title")
.withRequestCode(FILE_PICKER_REQUEST_CODE)
.start()
...
但是我不知道如何实现这段代码。 我创建了一个名为
MaterialFilePicker.java
的文件,并将提供的代码修改为如下所示:
package com.infinityfreeapp.formalsoftware.audioplayer;
import java.util.regex.Pattern;
import MaterialFilePicker;
public class MaterialFilePicker {
public static final int FILE_PICKER_REQUEST_CODE = 989;
MaterialFilePicker() {
// Pass a source of context. Can be:
// .withActivity(Activity activity)
// .withFragment(Fragment fragment)
// .withSupportFragment(androidx.fragment.app.Fragment fragment)
.withActivity(this)
// With cross icon on the right side of toolbar for closing picker straight away
.withCloseMenu(true)
// Entry point path (user will start from it)
.withPath(alarmsFolder.absolutePath)
// Root path (user won't be able to come higher than it)
.withRootPath(externalStorage.absolutePath)
// Showing hidden files
.withHiddenFiles(true)
// Want to choose only jpg images
.withFilter(Pattern.compile(".*\\.(jpg|jpeg)$"))
// Don't apply filter to directories names
.withFilterDirectories(false)
.withTitle("Sample title")
.withRequestCode(FILE_PICKER_REQUEST_CODE)
.start();
}
}
但是还是错误百出