博主介绍:本人专注于Android/java/数据库/微信小程序技术领域的开发,以及有好几年的计算机毕业设计方面的实战开发经验和技术积累;尤其是在安卓(Android)的app的开发和微信小程序的开发,很是熟悉和了解;本人也是多年的Android开发人员;希望我发布的此篇文件可以帮助到您;
效果演示
一、跳转页面
1:选择图片
Intent choiceImage = new Intent(this, ChoiceLocalFileActivity.class); choiceImage.putExtra("msg", "img"); this.startActivityForResult(choiceImage, 10); 2:选择视频 Intent choiceVideo = new Intent(this, ChoiceLocalFileActivity.class); choiceVideo.putExtra("msg", "video"); this.startActivityForResult(choiceVideo, 10);
二、获取文件列表
1:获取图片列表
List<FileVideolModel> getImage() { String[] projection = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Video.Media.SIZE}; String orderBy = MediaStore.Images.Media.DISPLAY_NAME; Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; return getContentProvider(uri, projection, orderBy); }
2:获取视频列表
private List<FileVideolModel> getVideosInfo() { String[] thumbColumns = new String[]{ MediaStore.Video.Thumbnails.DATA, MediaStore.Video.Thumbnails.VIDEO_ID }; ContentResolver contentResolver = getContentResolver(); String[] videoColumns = new String[]{ MediaStore.Video.Media._ID, MediaStore.Video.Media.DATA, MediaStore.Video.Media.TITLE, MediaStore.Video.Media.SIZE, MediaStore.Video.Media.MIME_TYPE }; List<FileVideolModel> listImage = new ArrayList<FileVideolModel>(); FileVideolModel fileVideolModel; Cursor cursor = contentResolver.query (MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoColumns, null, null, null); while (cursor.moveToNext()) { String _id = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID)); String filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); String title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE)); String mime_type = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE)); int SIZE = cursor.getColumnIndex(MediaStore.Video.Media.SIZE); Log.i("pony_log", "_id=" + _id); Log.i("pony_log", "title=" + title); Log.i("pony_log", "filePath=" + filePath); Log.i("pony_log", "mime_type=" + mime_type); //获取当前Video对应的Id,然后根据该ID获取其Thumb String selection = MediaStore.Video.Thumbnails.VIDEO_ID +"=?"; String[] selectionArgs = new String[]{_id}; Cursor thumbCursor = this.managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, thumbColumns, selection, selectionArgs, null); if(thumbCursor.moveToFirst()){ Log.i("pony_log", "thumbPath=" + cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Thumbnails.DATA))); } //获取当前Video对应的Id,然后根据该ID获取其Thumb int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID)); BitmapFactory.Options options = new BitmapFactory.Options(); options.inDither = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap infor = MediaStore.Video.Thumbnails.getThumbnail(getContentResolver(), id, MediaStore.Images.Thumbnails.MICRO_KIND, options); fileVideolModel = new FileVideolModel(); fileVideolModel.setFileName(title); fileVideolModel.setFilePath(filePath); fileVideolModel.setFileSize(cursor.getString(SIZE)); fileVideolModel.setFileUrl(infor); listImage.add(fileVideolModel); } return listImage; }
三、回调显示
private String imagePath; private String videoPath; private String imageName; private String videoName; @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode==1){ intentFlag = 1; imagePath = data.getStringExtra("msg"); imageName = data.getStringExtra("name"); choiceImage.setText(imageName); }else{ intentFlag = 10; videoPath = data.getStringExtra("msg"); videoName = data.getStringExtra("name"); choiceVideo.setText(videoName); } }
留个脚印吧!
大家点赞、收藏、关注、评论啦 ;
希望可以帮助到您;