Skip to content

Instantly share code, notes, and snippets.

@arulwastaken
Created January 23, 2021 15:27
Show Gist options
  • Save arulwastaken/7cdc6c1f079cf3f8168d396da7177b09 to your computer and use it in GitHub Desktop.
Save arulwastaken/7cdc6c1f079cf3f8168d396da7177b09 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
val camIntentCode = 100
val imageFile: File by lazy {
File(getExternalFilesDir(null)?.absolutePath + "/${System.currentTimeMillis()}.jpg")
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
fun OnGetImage(view: View) {
val camIntent = Intent(this@MainActivity, CameraXActivity::class.java)
camIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageFile.absolutePath)
startActivityForResult(camIntent, camIntentCode)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == camIntentCode) {
if (resultCode == RESULT_OK) {
val myBitmap = BitmapFactory.decodeFile(imageFile.absolutePath)
findViewById<ImageView>(R.id.image).setImageBitmap(myBitmap)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment