How to Take a Photo Using The Camera And Display it in Android Imageview

  Рет қаралды 15,231

Coding Demos

Coding Demos

Күн бұрын

Hi and welcome to another tutorial from CodingDemos :)
In this tutorial, you will learn how to take pictures with the camera on Android Programmatically.
Here are the steps:
1- Open up Android Studio.
2- Initialize the Android image capture Intent inside Android button OnClickListener.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
3- Before you can call startActivityForResult(), you need to do some checking to ensure that there is an application that can handle this type of action. Otherwise, show an error Toast Message.
if(intent.resolveActivity(getPackageManager()) != null){
startActivityForResult(intent, CAMERA_ACTION_CODE);
}else{
Toast.makeText(MainActivity.this, "There is no app that support this action", Toast.LENGTH_SHORT).show();
}
4- Next you need to Override a method called onActivityResult. This method will allow you to access the data image captured by the camera.
5- You need to perform some checking first before you can access the captured image. You need to check for the requestCode, resultCode and whether the Intent data is null or not.
if(requestCode == CAMERA_ACTION_CODE && resultCode == RESULT_OK && data != null){
}
6- Inside that condition, you will retrieve the captured image data using a Bundle.
Bundle bundle = data.getExtras();
7- To be able to use the Bundle image value inside Android ImageView, you will need to use Android Bitmap.
Bitmap finalPhoto = (Bitmap) bundle.get("data");
8- Finally, you can show the image inside the imageview like this.
imageProfile.setImageBitmap(finalPhoto);
9- Now build and run the app to see the final result.
#androiddevelopment #androidprogramming #androidtutorial #androidstudio #androidstudiotutorial #java
Links:
Android photo Intent: developer.android.com/trainin...
Website: www.codingdemos.com
FaceBook: / codingdemos
Introduction 00:00
Final output 00:15
Android Studio project introduction 01:00
Using the Android Camera Intent 03:37
Check if the device supports this Intent 05:05
Android onActivityresult 10:00
Conclusion 20:00

Пікірлер: 37
@CodingDemos
@CodingDemos 4 жыл бұрын
Hey guys, I hope you liked this tutorial :) Comment below on topics you want me to cover next.
@mcifci
@mcifci 4 жыл бұрын
what happened to my comments, disappears when i share
@mcifci
@mcifci 4 жыл бұрын
what do you about bringing a photo from the gallery
@mcifci
@mcifci 4 жыл бұрын
okay, we brought the photo, what we will do next, so we can not save it firebase, we need uri, how can 'cast' this bundle to uri
@mcifci
@mcifci 4 жыл бұрын
Also, the photo taken by this camera is terrible, man, this event sucks :D:D
@areebahmed9091
@areebahmed9091 Жыл бұрын
How do we send this image in Second activity?
@user-rd9lw7mf7v
@user-rd9lw7mf7v 3 жыл бұрын
Thank you very much! helped me with my project!
@sorinaion1365
@sorinaion1365 3 жыл бұрын
Hello Sir, great tutorial because you explained very detailed each line of code ! Thank you !
@pxcheah9675
@pxcheah9675 3 жыл бұрын
Thanks , it helps me al lot , really
@davidk.3450
@davidk.3450 Жыл бұрын
Can you update for registerForActivityResult(ActivityResultContract, ActivityResultCallback) ?
@eugenioperoni1307
@eugenioperoni1307 3 жыл бұрын
Thanks
@noapinchasi3898
@noapinchasi3898 2 жыл бұрын
Very clear explenation!! I have an error: the StartActivityForResults is deprecated. how to fix it?
@CodingDemos
@CodingDemos 2 жыл бұрын
Hi, I did a tutorial that shows you how to fix that error. Here is the link: kzfaq.info/get/bejne/p7Vjeammp9i4Ynk.html
@franz7770
@franz7770 3 жыл бұрын
but how do we do it with a full size photo?
@angelikakreutzer3182
@angelikakreutzer3182 Жыл бұрын
Could you do a Video for image classification with tf?
@mcifci
@mcifci 4 жыл бұрын
what about gallery bro, do you have a video about pickup image from gallery
@tahsinmahmud4294
@tahsinmahmud4294 3 жыл бұрын
can you please upload the code in github and share the link in description.
@nolep5555
@nolep5555 2 жыл бұрын
2022 still work :)
@mcifci
@mcifci 4 жыл бұрын
what about pick up image from gallery
@CodingDemos
@CodingDemos 4 жыл бұрын
Hi, I'm sorry but I don't have a tutorial that covers it.
@mcifci
@mcifci 4 жыл бұрын
@@CodingDemos no problem ;)
@chrisca97
@chrisca97 2 жыл бұрын
startActivityForResult is deprecated :\ any idea on how to solve it?
@CodingDemos
@CodingDemos 2 жыл бұрын
Hi, I did a tutorial that explains the solution: kzfaq.info/get/bejne/p7Vjeammp9i4Ynk.html
@lyrem287
@lyrem287 3 жыл бұрын
i did everything you said, yet the image captured is not showing in the app? what could be causing this?
@sivapradeep977
@sivapradeep977 3 жыл бұрын
Same here
@CodingDemos
@CodingDemos 3 жыл бұрын
Do you guys get any error message in the logcat?
@AvengerGamingYT.
@AvengerGamingYT. 2 жыл бұрын
@@CodingDemos how to display that image in multiple activities
@CodingDemos
@CodingDemos 2 жыл бұрын
@@AvengerGamingYT. Hi, you can save the image that was captured by the camera inside a database, and then load that image into different activities.
@AvengerGamingYT.
@AvengerGamingYT. 2 жыл бұрын
@@CodingDemos plz share one demo
@jugadtricks1626
@jugadtricks1626 3 жыл бұрын
I am facing error this on android 11 .sorry image occure while capturing image in android studio
@woonie3134
@woonie3134 3 жыл бұрын
@AYAN KUMAR JANA ty
JPEG is Dying - And that's a bad thing
8:09
2kliksphilip
Рет қаралды 109 М.
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,8 МЛН
ЧУТЬ НЕ УТОНУЛ #shorts
00:27
Паша Осадчий
Рет қаралды 10 МЛН
Box jumping challenge, who stepped on the trap? #FunnyFamily #PartyGames
00:31
Family Games Media
Рет қаралды 19 МЛН
路飞太过分了,自己游泳。#海贼王#路飞
00:28
路飞与唐舞桐
Рет қаралды 39 МЛН
Android onActivityResult is Deprecated. What Do I Do Now?
7:48
Coding Demos
Рет қаралды 23 М.
Take Picture with Camera - Android Studio - Java
14:19
Atif Pervaiz
Рет қаралды 57 М.
Top 10 CSS One Liners That Will Blow Your Mind
13:34
developedbyed
Рет қаралды 934 М.
Modding TikTok to only show Cat Videos
29:12
Bryce Bostwick
Рет қаралды 91 М.
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,8 МЛН