Code
Android Studio Electric Eel | 2022.1.1 Patch 2
[Java]
String path = xxx; //path of the video in the App’s external storage
String fname = xxx; // file name of the video
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DISPLAY_NAME, fname);
values.put(MediaStore.Images.Media.MIME_TYPE, “video/avc”);
values.put(MediaStore.Images.Media.IS_PENDING, 1);
ContentResolver resolver = getApplicationContext().getContentResolver();
Uri collection = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
Uri item = resolver.insert(collection, values);
InputStream in = new FileInputStream( path );
try (OutputStream out = getContentResolver().openOutputStream(item)) {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
in.close();
in = null;
out.flush();
out.close();
}catch(Exception e) {
}
Note
InputStream in = getContentResolver().openInputStream( Uri.parse(path) )
// returns error: “No content provider”