Android Camera Integration to Take Photos (including Android 10, API 29)- Kotlin Tutorial

  Рет қаралды 48,987

Rahul Pandey

Rahul Pandey

Күн бұрын

Пікірлер: 225
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Timestamps if you want to jump to a particular spot in the video: 0:38- Two ways to integrate camera functionality in your app 2:12- How to get the image if you’re ok with a low quality image 5:14- Handling onActivityResult once the user has taken a picture with the camera 7:06- Demo of app capturing the low quality image 7:45- How to get a high quality image from the camera 10:33- Introducing the file provider to securely pass the file to the camera app 14:15- Demo of app capturing the high quality image
@JordanBuser
@JordanBuser 2 жыл бұрын
Great video - clear and concise, explaining the logic behind the code is sadly rare these days... subscribed!
@akashkumardas6521
@akashkumardas6521 4 жыл бұрын
Thanks bro, your English totally match with native English speaker
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Thanks Akash, my goal is simply to be as clear as possible 😊
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Want to build an Instagram clone on Android using the camera? Follow along in this series: kzbin.info/aero/PL7NYbSE8uaBDFULNYVBV8kCyaG6OyMeaq
@user-ec1dn3uz5k
@user-ec1dn3uz5k 3 жыл бұрын
Thanks alot rahul. love how clear and concise this tut was. You helped me fix a crash i was experience due to filepath. Would appreciate more tuts from this channel, heck i wouldnt mind a really good paid course from you, i like your style of teaching very much
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
thanks Sami for the feedback!
@stillpickinganame5350
@stillpickinganame5350 Жыл бұрын
What a clear and straight to the point explanation! Thank you for this amazing video! Keep up with the good work!
@imashnake_7151
@imashnake_7151 3 жыл бұрын
Jeez this is the most underrated channel I know. Great content Rahul!
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
wow, thanks Kamalesh!
@chiranjeevshubham690
@chiranjeevshubham690 Жыл бұрын
This is what I am looking for many days ❤️ Thanks Sir 🙏
@shabab239
@shabab239 2 жыл бұрын
Amazing!! I have been struggling with this for a long time. Thank you very much for this clear tutorial...
@hamooon
@hamooon 2 жыл бұрын
Wish I could give this more likes. Exactly what I needed
@aihoneyai1197
@aihoneyai1197 4 жыл бұрын
thank you for explaining the two ways cause I watch many tutorials but they have diff code and no explanation. this helps a lot.
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
I'm glad it's helpful 😊
@aihoneyai1197
@aihoneyai1197 4 жыл бұрын
@@RahulPandeyrkp keep up the good work!
@pavangonahal8920
@pavangonahal8920 2 жыл бұрын
Helped a lot! I don't know kotlin, I will understand the code and write it in java
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
nice
@notheory-norules5915
@notheory-norules5915 3 жыл бұрын
Dear Rahul Pandey -- if we should ever met in reallife just remind me that i Owe you a beer for that extraordinary informative tutorial .. Keep It Up
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
would love to get a drink with you 🥰
@hematogen50g
@hematogen50g 3 жыл бұрын
Maan I used to code in C# but today tried kotlin. It is so much easier to write and understand.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
if you encounter any issue around view references not being found, check out kzbin.info/www/bejne/qpqsZodnbKZ3a5Y
@romana8203
@romana8203 3 жыл бұрын
Awesome tutorial! Thank you, I learned a lot in a short amount of time here. Question.. I know it would certainly take some effort and time to do, but have you ever considered doing one on CameraX and exploiting the camera for some interesting sensor data or even just making an app that incorporates the camera as part of a camera app with more features? Maybe something that has a very basic filter / frame rate setting / time lapse component?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Thanks Roman! I don't have plans to do a CameraX tutorial but your idea does sound interesting! I'll write it down, but for now I haven't been doing much with the camera overall.
@bboydarknesz
@bboydarknesz 3 жыл бұрын
man this is very great video. anyway so we don't need to make request permission camera again ?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Once a permission granted, you don't ned to keep requesting it. But you should keep checking that it's granted (the user may revoke permissions anytime).
@abhishekpurohit8867
@abhishekpurohit8867 4 жыл бұрын
Very helpful video with clear explanations....thank you very much
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
You are welcome Abhishek!
@liewsyetchau7941
@liewsyetchau7941 2 жыл бұрын
Thanks for the info, mate !
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
No problem 👍
@terlanabaszade9221
@terlanabaszade9221 2 жыл бұрын
Very thanks sir. But app rotates image automatically
@vincentalcid2057
@vincentalcid2057 2 жыл бұрын
Thank you for this tutorial it helps our project a lot :)
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
Glad it helped!
@DiegoSanchez-nf5hm
@DiegoSanchez-nf5hm 2 жыл бұрын
Thanks man, nice video
@Zeptember97
@Zeptember97 3 жыл бұрын
Hi Rahul, Thank You so much!. I did try the first way and gonna do the second way now. :D
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Great! LMK how it goes!
@enamulhoque-td4il
@enamulhoque-td4il 4 жыл бұрын
thank you very much. your tutorial really helped me. keep it up.
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
thanks, enamul
@allexandrevieira350
@allexandrevieira350 4 жыл бұрын
Great video, mate! How do I make the photos that I take appear on the Google photos, or how do I save the photos into the DCIM folder?
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
You should be able to save the photo into the DCIM folder by using constant DIRECTORY_DCIM (instead of DIRECTORY_PICTURES)
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Here's a SO link: stackoverflow.com/questions/37848645/how-to-get-the-default-directory-of-photo-made-by-camera-in-android
@allexandrevieira350
@allexandrevieira350 4 жыл бұрын
@@RahulPandeyrkp Wow, thanks for your reply, you're the man! Well, if I only change getExternalFilesDir(Environment.DIRECTORY_PICTURES) to getExternalFilesDir(Environment.DIRECTORY_DCIM), the pictures still private to my app, just within a different folder name (DCIM instead of Pictures). In the stackoverflow answer, they suggest the use of getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), but I'm targeting Android 11 and getExternalStoragePublicDirectory isn't available. I should use something like MediaStore, but I haven't found a good tutorial on this one yet. So, I'm kind of stuck. Anyway, it's good to talk about programming with someone like you who is a good teacher. Thank you
@rohitprabhakaran99
@rohitprabhakaran99 2 жыл бұрын
very nice video @Rahul. can we have video related to download a large image from internet using various ways
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
I'll add it to my list
@michaelmueller238
@michaelmueller238 3 жыл бұрын
So helpful. Thank you!
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
My pleasure
@harishlodha8794
@harishlodha8794 2 жыл бұрын
Sir background video recorder app se user Jo video record karta hai kya vo video app developer ke pass bhi store hota hai kya
@jayceeddeyro1406
@jayceeddeyro1406 4 жыл бұрын
May I know why use linear layout instead of constraint layout?
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Hi Jayceed, definitely! If the layout is simple enough, I prefer using LinearLayout since it's easier to reason about; it's clear how elements are laid out on the screen. ConstraintLayout is more powerful but also a bit harder to parse.
@joshuarandezperez666
@joshuarandezperez666 Жыл бұрын
why does my screen turn into black when I use a fragment?
@MrRahulmalik
@MrRahulmalik 4 жыл бұрын
Make more videos man! Cheers Make a video on Apollo Graphql with complex queries
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
I'll add it to the list!
@emmanuelpregnolato5026
@emmanuelpregnolato5026 3 жыл бұрын
Thank you Rahul.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Pleasure is mine
@bhushan2k
@bhushan2k 4 жыл бұрын
Great explanation. Easy to integrate. I wanted to know how to open front camera by default without toggling? I need to do employee attendance with selfie in office project. So this is their requirement.
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Unfortunately there's no officially supported way to open the front camera. You can try intent.putExtra("android.intent.extras.CAMERA_FACING", 1); but the camera app that opens up has the choice to honor this or not. If you really want this control over the camera, you should embed it into your app.
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
discussion from SO: stackoverflow.com/questions/19667094/intent-does-not-set-the-camera-parameters/19670928#19670928
@abdullahaddoun5720
@abdullahaddoun5720 2 жыл бұрын
THANK YOU SO MUCH DUDE 😁
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
My pleasure 🥰
@poojasaini1236
@poojasaini1236 3 жыл бұрын
I am getting this error in Android 10 device - MIME type Image/jpg cannot be inserted into content://media/external/images/media; expected MIME type under image/*
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
I haven't seen that error before. Some googling led me to this: stackoverflow.com/questions/63387961/how-to-save-bitmap-image-into-internal-storage-of-phone Does it happen on all devices you tried?
@trickydotworld
@trickydotworld 3 жыл бұрын
Hello Rahul Pandey, I implemented your code successfully and the image is showing in the ImageView but i have one problem. the image is not showing in the phone gallery. please help me. thank you
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
That's expected in this video since we did not write the photo back to the gallery. You'll need to add the WRITE_EXTERNAL_STORAGE permission- here's an SO post stackoverflow.com/a/17426328/875700
@trickydotworld
@trickydotworld 3 жыл бұрын
@@RahulPandeyrkp thanks you Rahul Pandey for the quick response. One thing more that i wanna to ask. i am totally confused in giving the permissions. I implemented your code and did not give any runtime permissions but still it works. also the documentation says " In particular, if your app targets Android 11 (API level 30) or higher, the WRITE_EXTERNAL_STORAGE permission doesn't have any effect on your app's access to storage" . SO please explain whether the runtime permission is required on the latest version or not. if not then will it work on the old versions as well ??? i will be very thankful to you
@kibirigejohn8324
@kibirigejohn8324 3 жыл бұрын
Thank you
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
You're welcome!
@AnikenSkiwalker
@AnikenSkiwalker 3 жыл бұрын
Thanks for the video.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
My pleasure
@BigCityLifeeee
@BigCityLifeeee 3 жыл бұрын
when saving, duplicates are obtained, one photo file is created in the path where I indicated, and the second in DCIM/CAMERA. How fix that?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
We create a temp file at the location specified, as per File.createTempFile(... Are you still seeing duplicates if you navigate via the file explorer?
@cabecaguidao6315
@cabecaguidao6315 2 жыл бұрын
hello, I would like to know how I could do this process, but on the contrary, the camera requests the image and I pull it from the directory, thank you.
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
There's a different implicit intent for that. I cover it in the MyMemory tutorial series on my channel.
@shubhamgupta5770
@shubhamgupta5770 2 жыл бұрын
Hello, Can you make a video "How to implement twilio video calling function" step by step ?
@ramyagowda2976
@ramyagowda2976 3 жыл бұрын
Image captured using camera intent gets rotated by 45° ... How to solve this ?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
can you check the orientation of the phone when the camera is launched? stackoverflow.com/questions/14066038/why-does-an-image-captured-using-camera-intent-gets-rotated-on-some-devices-on-a
@thomasblauensteiner1000
@thomasblauensteiner1000 4 жыл бұрын
thanks bro you are the best ; )
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Thank you 💖
@joemarandres3133
@joemarandres3133 2 жыл бұрын
This was really great sir, I already integrate the camera on my application. I just have a concern because when I run the app on my android device, I tried also your code to run on my device but the image that was shown was rotated 90 degrees counter clockwise. Do you know any solution about this? Thank you in advance sir
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
Does that also happen on a real phone? I've seen this on am emulator but not a real phone
@joemarandres3133
@joemarandres3133 2 жыл бұрын
@@RahulPandeyrkp actually I'm debugging it on my physical hadset sir
@joemarandres3133
@joemarandres3133 2 жыл бұрын
@@RahulPandeyrkp do you have any solution on this sir?
@shania5214
@shania5214 Жыл бұрын
I have the same problem
@anonymouspanda689
@anonymouspanda689 4 жыл бұрын
Great video! I had a quick question. How do I have a camera in a fragment? I tried your method but it doesn't seem to be working for fragments and only for activities. Thanks for the help!!
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Does the intent to launch the camera succeed from the fragment? Call method startActivityForResult (and not getActivity().startActivityForResult). If you're not getting data back in your fragment, make sure you're calling super.onActivityResult() from the parent Activity of the Fragment, if you have overridden that method.
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
SO link: stackoverflow.com/questions/6147884/onactivityresult-is-not-being-called-in-fragment
@anonymouspanda689
@anonymouspanda689 4 жыл бұрын
@@RahulPandeyrkp Hi! So sorry for the late response. Thank you so much for helping me. Here is the error I get: AndroidRuntime: FATAL EXCEPTION: main Process: com.example.---, PID: 8697 java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE cmp=com.android.camera2/com.android.camera.CaptureActivity } from ProcessRecord{22f3698 8697:com.example.-----/u0a86} (pid=8697, uid=10086) with revoked permission android.permission.CAMERA at android.os.Parcel.createException(Parcel.java:1950) Do you understand what exactly went wrong when I clicked "take picture"? Thanks :)
@shivamsethi3829
@shivamsethi3829 3 жыл бұрын
great topic, cheers
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
thanks Shivam
@RohitKumar-rb8wu
@RohitKumar-rb8wu 3 жыл бұрын
same file provider code feasible for android 11 or not ?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Yes, should still work on Android 11. If you have any issues, please LMK .
@patrickFREE.
@patrickFREE. 3 жыл бұрын
Awesome!
@tommyma5039
@tommyma5039 2 жыл бұрын
Thanks for the tutorial, at 6.16, i cannot find setimageBitmap, there is only drawtobimap function, are they the same?
@Darkmatterkun
@Darkmatterkun 2 жыл бұрын
Hey, when I click the confirm button on the camera app, my app loads on the home screen. Please help I'm getting the following errors - Accessing hidden method, FATAL EXCEPTION: main
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
Sounds like the app crashed - can you open up logcat and look lower into the stack trace?
@Darkmatterkun
@Darkmatterkun 2 жыл бұрын
SOLVED. The id I was referring to was wrong. @@RahulPandeyrkp Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference.
@RohitKumar-rb8wu
@RohitKumar-rb8wu 3 жыл бұрын
Hi rahul, i dont want to save clicked picture in Pictures directory and want to save same in app internal storage. How can i achieve that?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
you can try this approach: stackoverflow.com/questions/17674634/saving-and-reading-bitmaps-images-from-internal-memory-in-android
@alexcasillas4508
@alexcasillas4508 2 жыл бұрын
How come startActivityForResult is an error? When I get a suggestion it has it but it's crossed out. Is there something I'm missing?
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
it's deprecated but can still be used: stackoverflow.com/questions/62671106/onactivityresult-method-is-deprecated-what-is-the-alternative
@КонстантинАлександров-п4д
@КонстантинАлександров-п4д 2 ай бұрын
Доброго времени суток. Устройство Teyes сс3 6/128. Как заставить работать это устройство,и вообще все андроид магнитолы,с таксометртом Яндекс.Про? Проблема в отсутствии у подобных устройств встроенной камеры, которая нужна для прохождения фотоконтроля личности. Вообще для таксометра яндекса нужно много чего фоткать именно устройством на котором работаешь,например фотоконтроль машины и различных документов,но это все можно сделать и на другом устройстве,например на телефоне. Но если после прохождения всех фотоконтролей перейти на другое устройство, в данном моем случае на андроид магнитолу, то программа потребует сделать сельфи,так как произошла замена устройств. Собственно как сделать это селфи? Как собственно возможно ли доработать устройство?
@statwizard
@statwizard 4 жыл бұрын
Thanks for the video, greatly appreciated. How do you enable the on-board flash to take a cleaner image?
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
The implicit intent to open the camera will present the UI to control the camera, including options like flash or camera direction. You won't see it on the emulator since it won't have the required PackageManager.FEATURE_CAMERA_FLASH.
@statwizard
@statwizard 4 жыл бұрын
@@RahulPandeyrkp Thank you very much for the quick response and feedback.
@ChinhNguyen-eg5km
@ChinhNguyen-eg5km 4 жыл бұрын
in 10:20 i can not call storageDirectory, i dont have it why?? plss help
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Chinh, the method getExternalFilesDir is defined on a context: developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String). So you could try calling this@MyActivity.getExternalFilesDir to populate storageDirectory.
@divine-debug
@divine-debug Жыл бұрын
hey Rahul! it is saying ........On activity result, Start Activity for result is deprecated .... I am able to do it for explicit intents by "register for Activity Result" but in case of implicit intent it is returning BOOLEAN as second parameter , please help me with this
@RahulPandeyrkp
@RahulPandeyrkp Жыл бұрын
Yea the way to open an intent has changed but the way shown in the video still works
@divine-debug
@divine-debug Жыл бұрын
@@RahulPandeyrkp okay thanks for letting me know
@shubham5399
@shubham5399 3 жыл бұрын
Thank you so much :)
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
my pleasure!
@nishantpattani3053
@nishantpattani3053 3 жыл бұрын
Hi i have tried this but it’s not working please can you help me?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
What's the error you're seeing? What exactly is not working?
@kharismasenja7463
@kharismasenja7463 4 жыл бұрын
Do you have youtube video to explane how set auto max zoom camera when turn on
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
I don't know of a way to do this using the implicit ACTION_IMAGE_CAPTURE intent. You will be able to do this if you build your own custom camera activity, but I don't have a video about this (yet).
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
here's a SO link for more info: stackoverflow.com/questions/26697239/how-to-replace-mediastore-action-image-capture-with-a-custom-camera-activity
@assaultsquad6956
@assaultsquad6956 3 жыл бұрын
btnTakePicture.setOnClickListener ...why i not able to use this directly as you have used? I can only use setOnClickListener after using fingViewbyId(it has happened before in many other projects). Do i need to do something to use setOnClickListener directly without using findViewbyid ?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
This is likely not your fault, but a change in Android Studio due to version upgrades. I'd recommend you explicitly set the value of imageView in the onCreate method using findViewById
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Video with more details: kzbin.info/www/bejne/qpqsZodnbKZ3a5Y
@assaultsquad6956
@assaultsquad6956 3 жыл бұрын
@@RahulPandeyrkp thank you👍
@SevenPoundsful
@SevenPoundsful 3 жыл бұрын
How can i now acces the takenImage val in another function? Since you can't use the variable takenImage in another function, since its only in the onAcitivityResult function if I'm not mistaken. So let's say I want to use the Image we created and pass it into the TextRecognition function from ML Kit.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
You can derive the image file from the filepath where the pic was taken: BitmapFactory.decodeFile(photoFile.absolutePath)
@EnglishRain
@EnglishRain 3 жыл бұрын
Silly Question: At 03:45 when i type "btnTakePicture" i get an underline error saying "Unresolved reference". I've spelled it correctly in the activity_main.xml file, any idea why it is not detecting the ID that we gave it in the XML file? I'm using API 21 btw so that i can cover many devices.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
I am guessing you are using Android Studio 4.1? If so, this issue is caused by some changes in the plugins enabled by default. To fix, just add one line in the build.gradle file located in the app module, at the top of the file in the plugins section: id 'kotlin-android'
@EnglishRain
@EnglishRain 3 жыл бұрын
@@RahulPandeyrkp Thanks for the quick reply! I checked, yes i'm using AS 4.1 and id 'kotlin-android' is already present in the plugins section at the top. Is there any other error information that I could supply to you to help narrow down the issue?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
hmm... first can you remove the reference to btnTakePicture and see if you can build the project? If so, two things to try are going into File > Invalidate Caches/Restart and Build > Clean Project.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
and if that doesn't work, I'd simply move off kotlin android extensions and get a reference to the view on onCreate like this (after the call to setContentView): val btnTakePicture = findViewById(R.id.btnTakePicture)
@EnglishRain
@EnglishRain 3 жыл бұрын
@@RahulPandeyrkp Thanks man! Did "Invalidate Caches/Restart" + "Build > Clean Project" but still same reference error. I'm a total beginner so i totally forgot that i could just do it instead by findViewById like you said. So i just did that and now am carrying on with your tutorial. Thanks a ton for your time and help, highly appreciate it!
@muhamadazzamkusyairi2655
@muhamadazzamkusyairi2655 3 жыл бұрын
hello. the video was nice. may i know if this tutorial can be implemented in the real phone instead of emulator? becoz my laptop can't run the emulator so need to launch everything using real phone. thanks.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
yes, this should also work on a real phone as well!
@alostsoul9594
@alostsoul9594 Жыл бұрын
Could you make the same video in Java?
@damercy
@damercy 3 жыл бұрын
Hi Rahul. If we render the complete large sized image into an imageview, won't that have any performance implications? What would be the workaround then, if on one hand you need the file path but on the other hand, display a low quality image in the UI?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Dayamoy, that's a great point that it may indeed be wasteful to put a very large image into an ImageView which has much smaller dimensions. That's why most apps will use an image loading library such as Glide or Picasso which will take care of downsampling the image as needed.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
more reading about the implications of the method we're using, setImageBitmap: developer.android.com/topic/performance/graphics/load-bitmap
@damercy
@damercy 3 жыл бұрын
@@RahulPandeyrkp Damn! Thanks a lot man! ❤
@SabirAli-np7ci
@SabirAli-np7ci 2 жыл бұрын
Hello sir! I am using Navigation Component where I have one activity and multiple fragments and I want to integrate the ML Kit from Google to make an OCR Note App... The issue is how to open the camera ? shall I use Intent ? or something else because I have only one activity. Please do reply. ...
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
something similar should work!
@ravitejasunkara9477
@ravitejasunkara9477 3 жыл бұрын
Don't we add we need to add runtime camera permissions?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Nope, because we are using another application (the existing camera app) to access the camera
@shafqatali3065
@shafqatali3065 2 жыл бұрын
When we capture image and press OK, then app is crash....... An error is as follows :- 'The lateinit property photoFile is not initialized' How we fix this error. Help me asap
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
how is your code different from mine?
@shafqatali3065
@shafqatali3065 2 жыл бұрын
@@RahulPandeyrkp The code is same.... Nothing different
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
@@shafqatali3065 but the code in my github repo still working -- so it must be either an environment or code difference
@shafqatali3065
@shafqatali3065 2 жыл бұрын
@@RahulPandeyrkp I follow the exactly same code but on my side app is crash. The following error is shown in logcat:- Caused by: kotlin.UninitializedPropertyAccessException: lateinit property photoFile has not been initialized.
@needtools
@needtools 3 жыл бұрын
Thank you.
@needtools
@needtools 3 жыл бұрын
Dear Rahul Pandey, Your videos helped me a lot. Thank you. If it is posible please make a video how to use Picasso or Glide. I mean croping, deviding, resizing images etc. Thanks again.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
ooh that should be a nice quick one, let me do some research on that
@arnavkulshrestha562
@arnavkulshrestha562 3 жыл бұрын
my app is crashing because of startActivityForResult(takePictureIntent, REQUEST_CODE) this in if , can you tell me the reason and suggestion how to remove this error.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
what's the stack trace when you run the app? Can you ensure the phone/emulator you're running on has a camera?
@arnavkulshrestha562
@arnavkulshrestha562 3 жыл бұрын
@@RahulPandeyrkp yes, i have camera on my mobile phone and stack trace is showing me "at com.me.learningproject.MainActivity$onCreate$1.onClick(MainActivity.kt:35)" and 35th line is startActivityForResult(takePictureIntent, REQUEST_CODE)
@deppakkumar659
@deppakkumar659 4 жыл бұрын
How to work with camera x library
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Deepak, the approach in this video doesn't require working with camera X or any camera APIs. I might make a video about CameraX at some point later.
@deppakkumar659
@deppakkumar659 4 жыл бұрын
@@RahulPandeyrkp ok
@Aditya-dv5wg
@Aditya-dv5wg 4 жыл бұрын
After talking picture it is not displayed on screen ???
@Aditya-dv5wg
@Aditya-dv5wg 4 жыл бұрын
Please help me
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Are you able to get the low-quality image to show up? Can you make sure you're able to display a hardcoded drawable in the image view?
@Aditya-dv5wg
@Aditya-dv5wg 4 жыл бұрын
Yes it is showing up but after clicking pic it doesn't show in the desired place
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Need more info- where does it show up? Have you tried adding log statements?
@krishna247india8
@krishna247india8 4 жыл бұрын
Thanks bro for this great video. i want to call "startActivityForResult(takePictureIntent, reqCode)" from fragment or from dialog and get result in mainActivity is there any way to do this.
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Yes, it's possible! Try calling *getActivity(). startActivityForResult(...)*
@bhushan2k
@bhushan2k 3 жыл бұрын
you are creating temp file in picture directory of app's scope which needs READ_EXTERNAL_STORAGE as you have put in manifest but that permission is dangerous isn't it and needs to be asked on runtime?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
I believe you are correct, but the min API where this is enforced seems to be API 30, not 29. Does it work for you on a phone targeting API 29?
@bhushan2k
@bhushan2k 3 жыл бұрын
@@RahulPandeyrkp I guess it doesn't need permission to store file in app's storage irrespective of which API we are targeting. I checked ur code on API 30 as well as on 29, worked without any problem. kzbin.info/www/bejne/eWOboamaZ9WfeKM
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
@@bhushan2k thank you for testing and letting me know! I'll update the description
@solace3724
@solace3724 2 жыл бұрын
can you remake this video? Since the method startActivityForResult is deprecated, i find it super difficult to deal with acquiring result from others activity. Btw great video!
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
yep, I definitely plan on doing that at some point, but this method should still work in the meantime!
@claudiashemtov6294
@claudiashemtov6294 Жыл бұрын
@@RahulPandeyrkp Did you ever make this video?
@MrRahulmalik
@MrRahulmalik 4 жыл бұрын
hey how did you managed to Auto fill the Toast? I dont get that option.
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
I'm using live templates- if you type Toast, you should be able to use the template to automatically create Toast.makeText(, "", Toast.LENGTH_SHORT).show(). Here's an article about saving you some keystrokes using live templates: medium.com/google-developers/writing-more-code-by-writing-less-code-with-android-studio-live-templates-244f648d17c7.
@le7724
@le7724 4 жыл бұрын
Hi, great video. I dont know why but i cant access the camera. I tried debugging to it keeps going in Unable to open camera ? I did exactly what you did... I am using Androi studio 4.0 and i have targetSdkVersion 30
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Are there any logs associated with the error? What hardware are you running on?
@le7724
@le7724 4 жыл бұрын
@@RahulPandeyrkp no, when I launched the app I only get in the unable to open camera. Running the app on pixel 3a.
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
@@le7724 sorry I don't quite follow "get in the unable to open camera." I'd try to add logs on the button click and also look at generic logs (warning or error level) to see if there are any hints about something going wrong.
@le7724
@le7724 4 жыл бұрын
@@RahulPandeyrkp hi, So I put a breakpoint right before the if statement to see if it goes in but it doesn't. It goes in the else statement where we print out the unable to open camera. I will try to see if there any logs or error.. Thank you , will keep you updated
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
@@le7724 resolveActivity returning null means that there's no app which handles that intent. I wonder if it's due to a new restriction in API 30 - can you set the target API to 29 and see if that fixes the issue?
@alirehan4797
@alirehan4797 4 жыл бұрын
after pic capturing didn't show in image view?
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
Can you check the file path of the photo taken and make sure it's sensible? Put a log statement inside onActivityResult to see what data you're getting back.
@real_redemtor4441
@real_redemtor4441 3 жыл бұрын
Hello ! Thanks for the video but I am having a problem. The ".setImageBitmap" is red in my code and it doesn't recognize the command. I am completetly new to this so pls help me.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
This is likely not your fault, but a change in Android Studio due to version upgrades. I'd recommend you explicitly set the value of imageView in the onCreate method using findViewById
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Video with more details: kzbin.info/www/bejne/qpqsZodnbKZ3a5Y
@franciscomurcia4164
@franciscomurcia4164 2 жыл бұрын
write this: val takenImage = data?.extras?.get("data") as Bitmap binding.imageView.setImageBitmap(takenImage)
@FattieBB
@FattieBB 3 жыл бұрын
Thanks a lot Rahul it was really helpful
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Glad to hear that 🤗
@juanellatoso
@juanellatoso 3 жыл бұрын
Someone know how to do this but with Android 11?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
I haven't tried, but I believe this should work. If not, please LMK and I'll update the repo with the changes.
@re-codee
@re-codee 4 жыл бұрын
6:27 is it possible with minSdkVersion 16?
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
It should work, but depending on what you're trying to do, you may need to add the WRITE_EXTERNAL_STORAGE permission (needed up till SDK 18)
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
documentation link: developer.android.com/training/camera/photobasics#TaskPath
@FaTaLxNoodlesx
@FaTaLxNoodlesx 4 жыл бұрын
Does this save the file locally too?
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
The file is saved to disk at location of getExternalFilesDir, which is the absolute path to the directory of the shared storage on your phone. We use File.createTempFile, which creates a file with a unique/random name, but it is still saved locally. developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String)
@tomwilliam7299
@tomwilliam7299 2 жыл бұрын
could you please put the github of this code please ? 🙂🙂☺️☺️☺️☺️☺️☺️☺️☺️
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
github.com/rpandey1234/CameraIntegration
@linqcodmax8965
@linqcodmax8965 3 жыл бұрын
Good tutorial! But, at the end ive got an issue: java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/com.linqcod.recipeapp/files/Pictures/photo492757761155455089.jpg So can u say how to solve it please)
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Instead of using
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
see stackoverflow.com/questions/42516126/fileprovider-illegalargumentexception-failed-to-find-configured-root
@RahulKumar-xr9yq
@RahulKumar-xr9yq 4 жыл бұрын
How to live filter but not with ar
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
hey Rahul, can you clarify what you mean? For more control over the camera experience, you can embed the camera into your app. See this video: kzbin.info/www/bejne/eJqXgp2Dm7iCe5I
@saritagandhi8029
@saritagandhi8029 3 жыл бұрын
How to open the front camera by default?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
Unfortunately there's no officially supported way to open the front camera. You can try intent.putExtra("android.intent.extras.CAMERA_FACING", 1); but the camera app that opens up has the choice to honor this or not. If you really want this control over the camera, you should embed it into your app.
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
discussion from SO: stackoverflow.com/questions/19667094/intent-does-not-set-the-camera-parameters/19670928#19670928
@saritagandhi8029
@saritagandhi8029 3 жыл бұрын
@@RahulPandeyrkp Thanks for the reply. I tried with intent.putExtra("android.intent.extras.CAMERA_FACING", 1) but this extra parameter is ignored by the app.
@Srivatsa224
@Srivatsa224 4 жыл бұрын
Hi, I am facing an issue, the app is crashing, says" getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array" The error is pointing to this line " takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,fileProvider)" and StackOverflow says add external storage permission. But, I have already added. Can you please check my code and let me know what's wrong? github.com/Srivatsa224/Camera-Integration
@Srivatsa224
@Srivatsa224 4 жыл бұрын
I could find the issues by myself after adding logs. Issue sorted(I had added camera permission in manifest)
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
@@Srivatsa224 glad you were able to fix it!
@patrickFREE.
@patrickFREE. 3 жыл бұрын
how i can save the image ?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
it should already be saved in the DCIM directory
@VishalKumar-xm5ue
@VishalKumar-xm5ue 4 жыл бұрын
I m getting error in getExternalFilesDir
@RahulPandeyrkp
@RahulPandeyrkp 4 жыл бұрын
How are you trying to call it? getExternalFilesDir is method defined on the context: developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String) So try explicitly calling it on the activity or application context.
@aleks2147
@aleks2147 3 жыл бұрын
startActivityForResult is deprecated, what else can I use?
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
You can use the new Activity Result API
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
developer.android.com/training/basics/intents/result
@prathameshjadhav5212
@prathameshjadhav5212 3 жыл бұрын
How to with method 2??
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
why doesn't it work for you currently?
@prathameshjadhav5212
@prathameshjadhav5212 3 жыл бұрын
@@RahulPandeyrkp not like that it worked fine, but I want to apply some in came features so I needed in app camera
@RahulPandeyrkp
@RahulPandeyrkp 3 жыл бұрын
@@prathameshjadhav5212 these approaches are about using the existing camera app instead of building one in your app
@yusuffadhillah2977
@yusuffadhillah2977 2 жыл бұрын
how to post it to API ?
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
can you clarify your question? what are you trying to do? I cover uploading/downloading images to Firebase in the MyMemory tutorial
@RahulPandeyrkp
@RahulPandeyrkp 2 жыл бұрын
this video: kzbin.info/www/bejne/i2TTfpWeedSBZ5Y
@yusuffadhillah2977
@yusuffadhillah2977 2 жыл бұрын
Ty ill watch it 🥰
FRAGMENTS - Android Fundamentals
17:29
Philipp Lackner
Рет қаралды 330 М.
Learn Kotlin in 12 Minutes
12:01
Rahul Pandey
Рет қаралды 325 М.
My daughter is creative when it comes to eating food #funny #comedy #cute #baby#smart girl
00:17
when you have plan B 😂
00:11
Andrey Grechka
Рет қаралды 63 МЛН
Amazing Parenting Hacks! 👶✨ #ParentingTips #LifeHacks
00:18
Snack Chat
Рет қаралды 20 МЛН
How to Build a Camera App With CameraX - Taking Photos
29:35
Philipp Lackner
Рет қаралды 40 М.
How to Build a Video Recorder With CameraX in Android
11:38
Philipp Lackner
Рет қаралды 10 М.
Take Photos Using the Camera with Jetpack Compose
14:24
Kilo Loco
Рет қаралды 15 М.
What is Meta actually like as an engineer? (by ex-Metamates)
12:06
Rahul Pandey
Рет қаралды 16 М.
The FULL Beginner to Pro Roadmap for Android Development in 2023
10:47
Philipp Lackner
Рет қаралды 258 М.
How to Support ALL Screen Sizes on Android - Full Guide
19:10
Philipp Lackner
Рет қаралды 113 М.
My daughter is creative when it comes to eating food #funny #comedy #cute #baby#smart girl
00:17