Created
January 23, 2021 15:27
-
-
Save arulwastaken/7cdc6c1f079cf3f8168d396da7177b09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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