android中调用系统功能 来显示本地相册图片 拍照 视频 音频功能
来源:互联网 发布:php递归算法经典实例 编辑:程序博客网 时间:2024/05/18 17:05
android中调用系统功能 来显示本地相册图片 拍照 视频 音频功能
效果图如下:
本地相册跟拍照可直接调用系统功能
Intent img = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);FileNames name = new FileNames();File appFile = createRootDirectory(APP_FILE_NAMES);File file = new File(appFile.getPath(),name.getImageName());this.setImgFile(file);img.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));context.startActivityForResult(img, flag);
Intent getAlbum = new Intent(Intent.ACTION_OPEN_DOCUMENT);getAlbum.setType("image/*");context.startActivityForResult(getAlbum, flag);
视频调用 在不同手机会出现录制失败 需要在Android4.4以上版本Uri转换
/*** 根据Uri获取图片绝对路径,解决Android4.4以上版本Uri转换 * @param imageUri*/@TargetApi(19)public String getImageAbsolutePath(Uri imageUri) { if (context == null || imageUri == null) return null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, imageUri)) { if (isExternalStorageDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); String[] split = docId.split(":"); String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } } else if (isDownloadsDocument(imageUri)) { String id = DocumentsContract.getDocumentId(imageUri); Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(contentUri, null, null); } else if (isMediaDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); String[] split = docId.split(":"); String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } String selection = MediaStore.Images.Media._ID + "=?"; String[] selectionArgs = new String[] { split[1] }; return getDataColumn(contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(imageUri.getScheme())) { // Return the remote address if (isGooglePhotosUri(imageUri)) return imageUri.getLastPathSegment(); return getDataColumn(imageUri, null, null); } // File else if ("file".equalsIgnoreCase(imageUri.getScheme())) { return imageUri.getPath(); } return null; } private String getDataColumn(Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; String column = MediaStore.Images.Media.DATA; String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } finally { if (cursor != null) cursor.close(); } return null; }
要根据uri来重新获取绝对路径
音频录制跟视频类似 不同型号手机不一定都能获取到,都是需通过uri来转换路径显示
在点击视频播放调用系统功能 部分会闪退 主要是手机型号,
Intent video = new Intent(Intent.ACTION_VIEW);video.setDataAndType(Uri.parse(path), "video/*");context.startActivity(video);
决解方案 就是直接使用自带的VideoView来播放视频
Intent intent = new Intent(mContext, VideoPlayActivity.class);Bundle bundle = new Bundle();bundle.putString("path",mList.get(pos).getPath());intent.putExtras(bundle);
videoView1 = (VideoView) findViewById(R.id.videoView1);Bundle bundle = getIntent().getExtras();file = bundle.getString("path");//获得拍摄的视频保存地址videoView1.setVideoPath(file);videoView1.start();videoView1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { finish(); }});
DEMO下载
1 0
- android中调用系统功能 来显示本地相册图片 拍照 视频 音频功能
- Java乔晓松-android中调用系统拍照功能并显示拍照的图片
- 在Android 中调用选择图片、视频、添加音频、录音、拍摄视频、拍照等其他的功能
- 在Android 中调用选择图片、视频、添加音频、录音、拍摄视频、拍照等其他的功能
- 在Android 中调用选择图片、视频、添加音频、录音、拍摄视频、拍照等其他的功能
- 在Android 中调用选择图片、视频、添加音频、录音、拍摄视频、拍照等其他的功能
- 在Android 中调用选择图片、视频、添加音频、录音、拍摄视频、拍照等其他的功能【转】
- 调用系统相机拍照获取图片或者从相册中调用本地图片显示问题
- android 调用系统相册和系统拍照功能的Demo
- Android拍照和相册+系统裁剪功能返回图片
- Android中拍照、图片、录音、视频和音频功能的方法和代码
- Android中拍照、图片、录音、视频和音频功能的方法和代码
- android调用系统的图片,视频,音频,录音,拍照
- android中调用系统相机拍照并访问本地相册
- Android系统中拍照功能的调用
- 在Android中调用图片、视频、音频、录音、拍照
- 在Android中调用图片、视频、音频、录音、拍照
- Android中通过Intent 调用图片、视频、音频、录音、拍照
- Java面试题1
- 《javascript设计模式与开发实践》阅读笔记(四)
- dp的物理大小
- spring相关类
- 浅谈CDN内容分发网络
- android中调用系统功能 来显示本地相册图片 拍照 视频 音频功能
- sun.misc.Unsafe的使用---使用堆外内存空间存储整形数组
- js处理层级数据结构的一些总结
- Android属性动画运用实例
- 问题解决1@hdfs实际数据和备份数据不一致
- Mybatis小结之动态sql
- JavaMail使用阿里云企业版邮箱发送邮件
- 安卓离线打包
- Android Notification 手机系统横幅弹出提示框调用