gpt4 book ai didi

java - FilePickerActivity.EXTRA_MODE、FilePickerActivity.MODE_FILE

转载 作者:行者123 更新时间:2023-12-01 19:24:04 24 4
gpt4 key购买 nike

我想从图库中获取视频,但我遇到显示手机一般内存的问题,如何解决?

 private void selectVideo()
{
Intent i = new Intent(this, FastScrollerFilePickerActivity.class);

i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false);
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE);

String searchFolder;

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String fileSearchPath = prefs.getString("fileSearchPath", "last-used");

switch(fileSearchPath)
{
case "last-used":
default:
prefs = getSharedPreferences(SHARED_PREFS_KEY, MODE_PRIVATE);
searchFolder = prefs.getString(PICKER_DIR_PREF, Environment.getExternalStorageDirectory().getPath());
break;

case "external":
searchFolder = Environment.getExternalStorageDirectory().getPath();
break;
}

i.putExtra(FilePickerActivity.EXTRA_START_PATH, searchFolder);
startActivityForResult(i, SELECT_FILE_REQUEST);
}

我想从图库中获取视频,但我遇到显示手机一般内存的问题,如何解决?

protected AbstractFilePickerFragment getFragment(@Nullable String startPath, int mode, boolean allowMultiple, boolean allowCreateDir, boolean allowExistingFile, boolean singleClick)
{
return getFragment(startPath, mode, allowMultiple, allowCreateDir);
}

protected AbstractFilePickerFragment<File> getFragment(
@Nullable final String startPath, final int mode, final boolean allowMultiple,
final boolean allowCreateDir) {
AbstractFilePickerFragment<File> fragment = new FastScrollerFilePickerFragment();
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
fragment.setArgs(startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
mode, allowMultiple, allowCreateDir, true, false);
return fragment;
}

最佳答案

您可以使用以下行启动视频选择器

    startActivityForResult(new Intent(Intent.ACTION_PICK,MediaStore.Video.Media.EXTERNAL_CONTENT_URI),
SELECT_FILE_REQUEST_CODE);

如果您的应用程序崩溃,它必须在 Logcat 中留下红色消息,这对于尝试让您理解问题非常有帮助。

现在,在您的 onActivityResult 方法中输入以下内容以获取您选择的视频的路径:

public void onActivityResult(int reqCode, int resCode, Intent data){
if(reqCode == SELECT_FILE_REQUEST_CODE){
Uri selectedVideo = data.getData();
String[] filePathColumn = { MediaStore.Video.Media.DATA };

Cursor cursor = getContentResolver().query(selectedVideo,
filePathColumn, null, null, null);
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String videoPath = cursor.getString(columnIndex);
cursor.close();
}
}

关于java - FilePickerActivity.EXTRA_MODE、FilePickerActivity.MODE_FILE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59328018/

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