Android的MediaStore insertVideoAndroid、MediaStore、insertVideo

2023-09-05 00:34:16 作者:對不起丶妳沒有訪問權限

所以,我们的应用程序有选择采取任何图片或视频。如果用户需要的图片,我们可以使用MediaStore.Images.Media.insertImage功能来添加新的图像(通过文件路径)到手机的相册,并生成内容://风格的URI。是否有一个类似的过程中捕捉的视频,因为我们只有它的文件路径?

So our app has the option to take either a picture or a video. If the user takes a picture, we can use the MediaStore.Images.Media.insertImage function to add the new image (via a filepath) to the phone's gallery and generate a content:// style URI. Is there a similar process for a captured video, given that we only have it's filepath?

推荐答案

下面是一个简单的单个文件的解决方案:

Here is an easy 'single file based solution':

每当您添加一个文件,让MediaStore内容提供商知道它使用

Whenever you add a file, let MediaStore Content Provider knows about it using

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(imageAdded)));

主要优点:与MediaStore支持的MIME类型的工作

Main advantage: work with any mime type supported by MediaStore

对于删除:只需使用getContentResolver()删除(URI,NULL,NULL)

For deletion: just use getContentResolver().delete(uri, null, null)