"How to create a video file path on Android 10" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "How to create a video file path on Android 10" answered properly. Developers are finding an appropriate answer about How to create a video file path on Android 10 related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like How to create a video file path on Android 10. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on How to create a video file path on Android 10.
How to create a video file path on Android 10
private fun saveMediaFile2(filePath: String?, isVideo: Boolean, fileName: String) {
filePath?.let {
val context = MyApp.applicationContext
val values = ContentValues().apply {
val folderName = if (isVideo) {
Environment.DIRECTORY_MOVIES
} else {
Environment.DIRECTORY_PICTURES
}
put(MediaStore.Images.Media.DISPLAY_NAME, fileName)
put(MediaStore.Images.Media.MIME_TYPE, MimeUtils.guessMimeTypeFromExtension(getExtension(fileName)))
put(MediaStore.Images.Media.RELATIVE_PATH, folderName + "/${context.getString(R.string.app_name)}/")
put(MediaStore.Images.Media.IS_PENDING, 1)
}
val collection = if (isVideo) {
MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)
} else {
MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)
}
val fileUri = context.contentResolver.insert(collection, values)
fileUri?.let {
if (isVideo) {
context.contentResolver.openFileDescriptor(fileUri, "w").use { descriptor ->
descriptor?.let {
FileOutputStream(descriptor.fileDescriptor).use { out ->
val videoFile = File(filePath)
FileInputStream(videoFile).use { inputStream ->
val buf = ByteArray(8192)
while (true) {
val sz = inputStream.read(buf)
if (sz <= 0) break
out.write(buf, 0, sz)
}
}
}
}
}
} else {
context.contentResolver.openOutputStream(fileUri).use { out ->
val bmOptions = BitmapFactory.Options()
val bmp = BitmapFactory.decodeFile(filePath, bmOptions)
bmp.compress(Bitmap.CompressFormat.JPEG, 90, out)
bmp.recycle()
}
}
values.clear()
values.put(if (isVideo) MediaStore.Video.Media.IS_PENDING else MediaStore.Images.Media.IS_PENDING, 0)
context.contentResolver.update(fileUri, values, null, null)
}
}
}
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on How to create a video file path on Android 10 can get a collection of related answers to their query. Programmers need to enter their query on How to create a video file path on Android 10 related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about How to create a video file path on Android 10 for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of How to create a video file path on Android 10 while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "How to create a video file path on Android 10". Visit this developer's friendly online web community, CodeProZone, and get your queries like How to create a video file path on Android 10 resolved professionally and stay updated to the latest Whatever updates.