Android图片选择库仅选择视频(不包括图片)
创始人
2024-08-21 21:30:09
0

你可以使用Android图片选择库来仅选择视频而不包括图片的解决方法如下:

  1. 首先,添加以下依赖项到你的app的build.gradle文件中:
dependencies {
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    implementation 'com.github.Mariovc:ImagePicker:1.7.4'
}
  1. 在你的AndroidManifest.xml文件中添加以下权限:

  1. 创建一个新的Activity,用于选择视频:
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.nguyenhoanglam.imagepicker.model.Config;
import com.nguyenhoanglam.imagepicker.ui.imagepicker.ImagePicker;

public class VideoPickerActivity extends AppCompatActivity {

    private static final int REQUEST_VIDEO_PICKER = 101;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 图片选择配置
        Config config = new Config();
        config.setToolbarTitleRes(R.string.video_picker_title); // 设置标题
        config.setSelectionLimit(1); // 设置选择限制为1个视频
        config.setShowCamera(false); // 不显示相机选项
        config.setShowVideo(true); // 只显示视频选项

        // 启动图片选择器
        ImagePicker.with(this)
                .setConfig(config)
                .setRequestCode(REQUEST_VIDEO_PICKER)
                .start();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == REQUEST_VIDEO_PICKER && resultCode == RESULT_OK && data != null) {
            // 获取选择的视频Uri
            Uri videoUri = data.getData();

            // 处理选中的视频
            // 在这里你可以上传视频、预览视频等等
        }

        // 关闭当前Activity
        finish();
    }
}
  1. 在你的应用中调用该Activity以选择视频:
Intent intent = new Intent(this, VideoPickerActivity.class);
startActivity(intent);

这样,你的应用将会打开一个只能选择视频的图片选择器。用户选择完视频后,你可以在onActivityResult方法中获取到选中视频的Uri,并进行后续处理。

相关内容

热门资讯

玩家实测!fishpoker透... 玩家实测!fishpoker透视底牌,xpoker透视辅助,分享教程(有挂技巧)1、点击下载安装,微...
揭秘几款!hhpoker有辅助... 1、揭秘几款!hhpoker有辅助吗,wepoker脚本下载,第三方教程(有挂辅助);详细教程。2、...
总算清楚!wepoker祈福有... 总算清楚!wepoker祈福有用吗,wepoker私人局怎么玩,攻略教程(有挂方法);玩家必备必赢加...
记者揭秘!aapoker辅助怎... 记者揭秘!aapoker辅助怎么用,hhpoker是真的还是假的,专业教程(有挂技巧);hhpoke...
盘点一款!epoker透视底牌... 1、盘点一款!epoker透视底牌,大菠萝免费辅助,详细教程(有挂辅助);详细教程。2、大菠萝免费辅...
重大通报!wepoker高级辅... 1、重大通报!wepoker高级辅助,wepoker国外版透视,规律教程(有挂技巧);详细教程。2、...
一秒答解!wepoker究竟有... 一秒答解!wepoker究竟有没有透视,hhpoker脚本下载,介绍教程(有挂透明);建议优先通过w...
每日必备!aapoker公共底... 1、每日必备!aapoker公共底牌,wepoker底牌透视脚本,攻略方法(有挂软件)(UU pok...
今日百科!wepoker破解游... 今日百科!wepoker破解游戏盒子,hardrock透视工具,新2025教程(有挂软件)是由北京得...
1.9分钟了解!wepoker... 自定义wepoker私人局俱乐部辅助系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专...