You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/**
* An [ActivityResultContract] to
* [take small a picture][MediaStore.ACTION_IMAGE_CAPTURE] preview, returning it as a
* [Bitmap].
*
* This can be extended to override [createIntent] if you wish to pass additional
* extras to the Intent created by `super.createIntent()`.
*/
open class TakePicturePreview : ActivityResultContract<Void?, Bitmap?>() {
@CallSuper
override fun createIntent(context: Context, input: Void?): Intent {
return Intent(MediaStore.ACTION_IMAGE_CAPTURE)
}
final override fun getSynchronousResult(
context: Context,
input: Void?
): SynchronousResult<Bitmap?>? = null
@Suppress("DEPRECATION")
final override fun parseResult(resultCode: Int, intent: Intent?): Bitmap? {
return intent.takeIf { resultCode == Activity.RESULT_OK }?.getParcelableExtra("data")
}
}
/**
* An [ActivityResultContract] to
* [take a picture][MediaStore.ACTION_IMAGE_CAPTURE] saving it into the provided
* content-[Uri].
*
* Returns `true` if the image was saved into the given [Uri].
*
* This can be extended to override [createIntent] if you wish to pass additional
* extras to the Intent created by `super.createIntent()`.
*/
open class TakePicture : ActivityResultContract<Uri, Boolean>() {
@CallSuper
override fun createIntent(context: Context, input: Uri): Intent {
return Intent(MediaStore.ACTION_IMAGE_CAPTURE)
.putExtra(MediaStore.EXTRA_OUTPUT, input)
}
final override fun getSynchronousResult(
context: Context,
input: Uri
): SynchronousResult<Boolean>? = null
@Suppress("AutoBoxing")
final override fun parseResult(resultCode: Int, intent: Intent?): Boolean {
return resultCode == Activity.RESULT_OK
}
}
/**
* An [ActivityResultContract] to
* [take a video][MediaStore.ACTION_VIDEO_CAPTURE] saving it into the provided
* content-[Uri].
*
* Returns a thumbnail.
*
* This can be extended to override [createIntent] if you wish to pass additional
* extras to the Intent created by `super.createIntent()`.
*
*/
@Deprecated(
"""The thumbnail bitmap is rarely returned and is not a good signal to determine
whether the video was actually successfully captured. Use {@link CaptureVideo} instead."""
)
open class TakeVideo : ActivityResultContract<Uri, Bitmap?>() {
@CallSuper
override fun createIntent(context: Context, input: Uri): Intent {
return Intent(MediaStore.ACTION_VIDEO_CAPTURE)
.putExtra(MediaStore.EXTRA_OUTPUT, input)
}
final override fun getSynchronousResult(
context: Context,
input: Uri
): SynchronousResult<Bitmap?>? = null
@Suppress("DEPRECATION")
final override fun parseResult(resultCode: Int, intent: Intent?): Bitmap? {
return intent.takeIf { resultCode == Activity.RESULT_OK }?.getParcelableExtra("data")
}
}
/**
* An [ActivityResultContract] to
* [take a video][MediaStore.ACTION_VIDEO_CAPTURE] saving it into the provided
* content-[Uri].
*
* Returns `true` if the video was saved into the given [Uri].
*
* This can be extended to override [createIntent] if you wish to pass additional
* extras to the Intent created by `super.createIntent()`.
*/
open class CaptureVideo : ActivityResultContract<Uri, Boolean>() {
@CallSuper
override fun createIntent(context: Context, input: Uri): Intent {
return Intent(MediaStore.ACTION_VIDEO_CAPTURE)
.putExtra(MediaStore.EXTRA_OUTPUT, input)
}
final override fun getSynchronousResult(
context: Context,
input: Uri
): SynchronousResult<Boolean>? = null
@Suppress("AutoBoxing")
final override fun parseResult(resultCode: Int, intent: Intent?): Boolean {
return resultCode == Activity.RESULT_OK
}
}
The text was updated successfully, but these errors were encountered:
From ActivityResultContracts:
The text was updated successfully, but these errors were encountered: