class OpenCameraActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_open_camera)
findViewById<Button>(R.id.button).setOnClickListener {
if (Build.VERSION.SDK_INT > 29) {
test1()
} else {
test4()
}
}
}
private fun test4() {
val intent = Intent(Intent.ACTION_PICK)
intent.type = "video/*;image/*"
intent.action = Intent.ACTION_GET_CONTENT
startActivityForResult(
intent,
100
)
}
private fun test3() {
val intent = Intent(Intent.ACTION_PICK)
intent.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*")
startActivityForResult(intent, 200)
}
private fun test2() {
val intent = Intent(Intent.ACTION_PICK)
intent.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI, "video/*")
startActivityForResult(intent, 200)
}
private fun test1() {
val intent = Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
)
startActivityForResult(intent, 100)
}
}