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
@JordanBuser2 жыл бұрын
Great video - clear and concise, explaining the logic behind the code is sadly rare these days... subscribed!
@akashkumardas65214 жыл бұрын
Thanks bro, your English totally match with native English speaker
@RahulPandeyrkp4 жыл бұрын
Thanks Akash, my goal is simply to be as clear as possible 😊
@RahulPandeyrkp4 жыл бұрын
Want to build an Instagram clone on Android using the camera? Follow along in this series: kzbin.info/aero/PL7NYbSE8uaBDFULNYVBV8kCyaG6OyMeaq
@user-ec1dn3uz5k3 жыл бұрын
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
@RahulPandeyrkp3 жыл бұрын
thanks Sami for the feedback!
@stillpickinganame5350 Жыл бұрын
What a clear and straight to the point explanation! Thank you for this amazing video! Keep up with the good work!
@imashnake_71513 жыл бұрын
Jeez this is the most underrated channel I know. Great content Rahul!
@RahulPandeyrkp3 жыл бұрын
wow, thanks Kamalesh!
@chiranjeevshubham690 Жыл бұрын
This is what I am looking for many days ❤️ Thanks Sir 🙏
@shabab2392 жыл бұрын
Amazing!! I have been struggling with this for a long time. Thank you very much for this clear tutorial...
@hamooon2 жыл бұрын
Wish I could give this more likes. Exactly what I needed
@aihoneyai11974 жыл бұрын
thank you for explaining the two ways cause I watch many tutorials but they have diff code and no explanation. this helps a lot.
@RahulPandeyrkp4 жыл бұрын
I'm glad it's helpful 😊
@aihoneyai11974 жыл бұрын
@@RahulPandeyrkp keep up the good work!
@pavangonahal89202 жыл бұрын
Helped a lot! I don't know kotlin, I will understand the code and write it in java
@RahulPandeyrkp2 жыл бұрын
nice
@notheory-norules59153 жыл бұрын
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
@RahulPandeyrkp3 жыл бұрын
would love to get a drink with you 🥰
@hematogen50g3 жыл бұрын
Maan I used to code in C# but today tried kotlin. It is so much easier to write and understand.
@RahulPandeyrkp3 жыл бұрын
if you encounter any issue around view references not being found, check out kzbin.info/www/bejne/qpqsZodnbKZ3a5Y
@romana82033 жыл бұрын
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?
@RahulPandeyrkp3 жыл бұрын
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.
@bboydarknesz3 жыл бұрын
man this is very great video. anyway so we don't need to make request permission camera again ?
@RahulPandeyrkp3 жыл бұрын
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).
@abhishekpurohit88674 жыл бұрын
Very helpful video with clear explanations....thank you very much
@RahulPandeyrkp4 жыл бұрын
You are welcome Abhishek!
@liewsyetchau79412 жыл бұрын
Thanks for the info, mate !
@RahulPandeyrkp2 жыл бұрын
No problem 👍
@terlanabaszade92212 жыл бұрын
Very thanks sir. But app rotates image automatically
@vincentalcid20572 жыл бұрын
Thank you for this tutorial it helps our project a lot :)
@RahulPandeyrkp2 жыл бұрын
Glad it helped!
@DiegoSanchez-nf5hm2 жыл бұрын
Thanks man, nice video
@Zeptember973 жыл бұрын
Hi Rahul, Thank You so much!. I did try the first way and gonna do the second way now. :D
@RahulPandeyrkp3 жыл бұрын
Great! LMK how it goes!
@enamulhoque-td4il4 жыл бұрын
thank you very much. your tutorial really helped me. keep it up.
@RahulPandeyrkp4 жыл бұрын
thanks, enamul
@allexandrevieira3504 жыл бұрын
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?
@RahulPandeyrkp4 жыл бұрын
You should be able to save the photo into the DCIM folder by using constant DIRECTORY_DCIM (instead of DIRECTORY_PICTURES)
@RahulPandeyrkp4 жыл бұрын
Here's a SO link: stackoverflow.com/questions/37848645/how-to-get-the-default-directory-of-photo-made-by-camera-in-android
@allexandrevieira3504 жыл бұрын
@@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
@rohitprabhakaran992 жыл бұрын
very nice video @Rahul. can we have video related to download a large image from internet using various ways
@RahulPandeyrkp2 жыл бұрын
I'll add it to my list
@michaelmueller2383 жыл бұрын
So helpful. Thank you!
@RahulPandeyrkp3 жыл бұрын
My pleasure
@harishlodha87942 жыл бұрын
Sir background video recorder app se user Jo video record karta hai kya vo video app developer ke pass bhi store hota hai kya
@jayceeddeyro14064 жыл бұрын
May I know why use linear layout instead of constraint layout?
@RahulPandeyrkp4 жыл бұрын
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 Жыл бұрын
why does my screen turn into black when I use a fragment?
@MrRahulmalik4 жыл бұрын
Make more videos man! Cheers Make a video on Apollo Graphql with complex queries
@RahulPandeyrkp4 жыл бұрын
I'll add it to the list!
@emmanuelpregnolato50263 жыл бұрын
Thank you Rahul.
@RahulPandeyrkp3 жыл бұрын
Pleasure is mine
@bhushan2k4 жыл бұрын
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.
@RahulPandeyrkp4 жыл бұрын
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.
@RahulPandeyrkp4 жыл бұрын
discussion from SO: stackoverflow.com/questions/19667094/intent-does-not-set-the-camera-parameters/19670928#19670928
@abdullahaddoun57202 жыл бұрын
THANK YOU SO MUCH DUDE 😁
@RahulPandeyrkp2 жыл бұрын
My pleasure 🥰
@poojasaini12363 жыл бұрын
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/*
@RahulPandeyrkp3 жыл бұрын
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?
@trickydotworld3 жыл бұрын
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
@RahulPandeyrkp3 жыл бұрын
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
@trickydotworld3 жыл бұрын
@@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
@kibirigejohn83243 жыл бұрын
Thank you
@RahulPandeyrkp3 жыл бұрын
You're welcome!
@AnikenSkiwalker3 жыл бұрын
Thanks for the video.
@RahulPandeyrkp3 жыл бұрын
My pleasure
@BigCityLifeeee3 жыл бұрын
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?
@RahulPandeyrkp3 жыл бұрын
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?
@cabecaguidao63152 жыл бұрын
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.
@RahulPandeyrkp2 жыл бұрын
There's a different implicit intent for that. I cover it in the MyMemory tutorial series on my channel.
@shubhamgupta57702 жыл бұрын
Hello, Can you make a video "How to implement twilio video calling function" step by step ?
@ramyagowda29763 жыл бұрын
Image captured using camera intent gets rotated by 45° ... How to solve this ?
@RahulPandeyrkp3 жыл бұрын
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
@thomasblauensteiner10004 жыл бұрын
thanks bro you are the best ; )
@RahulPandeyrkp4 жыл бұрын
Thank you 💖
@joemarandres31332 жыл бұрын
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
@RahulPandeyrkp2 жыл бұрын
Does that also happen on a real phone? I've seen this on am emulator but not a real phone
@joemarandres31332 жыл бұрын
@@RahulPandeyrkp actually I'm debugging it on my physical hadset sir
@joemarandres31332 жыл бұрын
@@RahulPandeyrkp do you have any solution on this sir?
@shania5214 Жыл бұрын
I have the same problem
@anonymouspanda6894 жыл бұрын
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!!
@RahulPandeyrkp4 жыл бұрын
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.
@RahulPandeyrkp4 жыл бұрын
SO link: stackoverflow.com/questions/6147884/onactivityresult-is-not-being-called-in-fragment
@anonymouspanda6894 жыл бұрын
@@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 :)
@shivamsethi38293 жыл бұрын
great topic, cheers
@RahulPandeyrkp3 жыл бұрын
thanks Shivam
@RohitKumar-rb8wu3 жыл бұрын
same file provider code feasible for android 11 or not ?
@RahulPandeyrkp3 жыл бұрын
Yes, should still work on Android 11. If you have any issues, please LMK .
@patrickFREE.3 жыл бұрын
Awesome!
@tommyma50392 жыл бұрын
Thanks for the tutorial, at 6.16, i cannot find setimageBitmap, there is only drawtobimap function, are they the same?
@Darkmatterkun2 жыл бұрын
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
@RahulPandeyrkp2 жыл бұрын
Sounds like the app crashed - can you open up logcat and look lower into the stack trace?
@Darkmatterkun2 жыл бұрын
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-rb8wu3 жыл бұрын
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?
@RahulPandeyrkp3 жыл бұрын
you can try this approach: stackoverflow.com/questions/17674634/saving-and-reading-bitmaps-images-from-internal-memory-in-android
@alexcasillas45082 жыл бұрын
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?
@RahulPandeyrkp2 жыл бұрын
it's deprecated but can still be used: stackoverflow.com/questions/62671106/onactivityresult-method-is-deprecated-what-is-the-alternative
@КонстантинАлександров-п4д2 ай бұрын
Доброго времени суток. Устройство Teyes сс3 6/128. Как заставить работать это устройство,и вообще все андроид магнитолы,с таксометртом Яндекс.Про? Проблема в отсутствии у подобных устройств встроенной камеры, которая нужна для прохождения фотоконтроля личности. Вообще для таксометра яндекса нужно много чего фоткать именно устройством на котором работаешь,например фотоконтроль машины и различных документов,но это все можно сделать и на другом устройстве,например на телефоне. Но если после прохождения всех фотоконтролей перейти на другое устройство, в данном моем случае на андроид магнитолу, то программа потребует сделать сельфи,так как произошла замена устройств. Собственно как сделать это селфи? Как собственно возможно ли доработать устройство?
@statwizard4 жыл бұрын
Thanks for the video, greatly appreciated. How do you enable the on-board flash to take a cleaner image?
@RahulPandeyrkp4 жыл бұрын
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.
@statwizard4 жыл бұрын
@@RahulPandeyrkp Thank you very much for the quick response and feedback.
@ChinhNguyen-eg5km4 жыл бұрын
in 10:20 i can not call storageDirectory, i dont have it why?? plss help
@RahulPandeyrkp4 жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
Yea the way to open an intent has changed but the way shown in the video still works
@divine-debug Жыл бұрын
@@RahulPandeyrkp okay thanks for letting me know
@shubham53993 жыл бұрын
Thank you so much :)
@RahulPandeyrkp3 жыл бұрын
my pleasure!
@nishantpattani30533 жыл бұрын
Hi i have tried this but it’s not working please can you help me?
@RahulPandeyrkp3 жыл бұрын
What's the error you're seeing? What exactly is not working?
@kharismasenja74634 жыл бұрын
Do you have youtube video to explane how set auto max zoom camera when turn on
@RahulPandeyrkp4 жыл бұрын
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).
@RahulPandeyrkp4 жыл бұрын
here's a SO link for more info: stackoverflow.com/questions/26697239/how-to-replace-mediastore-action-image-capture-with-a-custom-camera-activity
@assaultsquad69563 жыл бұрын
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 ?
@RahulPandeyrkp3 жыл бұрын
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
@RahulPandeyrkp3 жыл бұрын
Video with more details: kzbin.info/www/bejne/qpqsZodnbKZ3a5Y
@assaultsquad69563 жыл бұрын
@@RahulPandeyrkp thank you👍
@SevenPoundsful3 жыл бұрын
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.
@RahulPandeyrkp3 жыл бұрын
You can derive the image file from the filepath where the pic was taken: BitmapFactory.decodeFile(photoFile.absolutePath)
@EnglishRain3 жыл бұрын
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.
@RahulPandeyrkp3 жыл бұрын
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'
@EnglishRain3 жыл бұрын
@@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?
@RahulPandeyrkp3 жыл бұрын
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.
@RahulPandeyrkp3 жыл бұрын
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)
@EnglishRain3 жыл бұрын
@@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!
@muhamadazzamkusyairi26553 жыл бұрын
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.
@RahulPandeyrkp3 жыл бұрын
yes, this should also work on a real phone as well!
@alostsoul9594 Жыл бұрын
Could you make the same video in Java?
@damercy3 жыл бұрын
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?
@RahulPandeyrkp3 жыл бұрын
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.
@RahulPandeyrkp3 жыл бұрын
more reading about the implications of the method we're using, setImageBitmap: developer.android.com/topic/performance/graphics/load-bitmap
@damercy3 жыл бұрын
@@RahulPandeyrkp Damn! Thanks a lot man! ❤
@SabirAli-np7ci2 жыл бұрын
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. ...
@RahulPandeyrkp2 жыл бұрын
something similar should work!
@ravitejasunkara94773 жыл бұрын
Don't we add we need to add runtime camera permissions?
@RahulPandeyrkp3 жыл бұрын
Nope, because we are using another application (the existing camera app) to access the camera
@shafqatali30652 жыл бұрын
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
@RahulPandeyrkp2 жыл бұрын
how is your code different from mine?
@shafqatali30652 жыл бұрын
@@RahulPandeyrkp The code is same.... Nothing different
@RahulPandeyrkp2 жыл бұрын
@@shafqatali3065 but the code in my github repo still working -- so it must be either an environment or code difference
@shafqatali30652 жыл бұрын
@@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.
@needtools3 жыл бұрын
Thank you.
@needtools3 жыл бұрын
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.
@RahulPandeyrkp3 жыл бұрын
ooh that should be a nice quick one, let me do some research on that
@arnavkulshrestha5623 жыл бұрын
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.
@RahulPandeyrkp3 жыл бұрын
what's the stack trace when you run the app? Can you ensure the phone/emulator you're running on has a camera?
@arnavkulshrestha5623 жыл бұрын
@@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)
@deppakkumar6594 жыл бұрын
How to work with camera x library
@RahulPandeyrkp4 жыл бұрын
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.
@deppakkumar6594 жыл бұрын
@@RahulPandeyrkp ok
@Aditya-dv5wg4 жыл бұрын
After talking picture it is not displayed on screen ???
@Aditya-dv5wg4 жыл бұрын
Please help me
@RahulPandeyrkp4 жыл бұрын
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-dv5wg4 жыл бұрын
Yes it is showing up but after clicking pic it doesn't show in the desired place
@RahulPandeyrkp4 жыл бұрын
Need more info- where does it show up? Have you tried adding log statements?
@krishna247india84 жыл бұрын
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.
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?
@RahulPandeyrkp3 жыл бұрын
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?
@bhushan2k3 жыл бұрын
@@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
@RahulPandeyrkp3 жыл бұрын
@@bhushan2k thank you for testing and letting me know! I'll update the description
@solace37242 жыл бұрын
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!
@RahulPandeyrkp2 жыл бұрын
yep, I definitely plan on doing that at some point, but this method should still work in the meantime!
@claudiashemtov6294 Жыл бұрын
@@RahulPandeyrkp Did you ever make this video?
@MrRahulmalik4 жыл бұрын
hey how did you managed to Auto fill the Toast? I dont get that option.
@RahulPandeyrkp4 жыл бұрын
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.
@le77244 жыл бұрын
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
@RahulPandeyrkp4 жыл бұрын
Are there any logs associated with the error? What hardware are you running on?
@le77244 жыл бұрын
@@RahulPandeyrkp no, when I launched the app I only get in the unable to open camera. Running the app on pixel 3a.
@RahulPandeyrkp4 жыл бұрын
@@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.
@le77244 жыл бұрын
@@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
@RahulPandeyrkp4 жыл бұрын
@@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?
@alirehan47974 жыл бұрын
after pic capturing didn't show in image view?
@RahulPandeyrkp4 жыл бұрын
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_redemtor44413 жыл бұрын
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.
@RahulPandeyrkp3 жыл бұрын
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
@RahulPandeyrkp3 жыл бұрын
Video with more details: kzbin.info/www/bejne/qpqsZodnbKZ3a5Y
@franciscomurcia41642 жыл бұрын
write this: val takenImage = data?.extras?.get("data") as Bitmap binding.imageView.setImageBitmap(takenImage)
@FattieBB3 жыл бұрын
Thanks a lot Rahul it was really helpful
@RahulPandeyrkp3 жыл бұрын
Glad to hear that 🤗
@juanellatoso3 жыл бұрын
Someone know how to do this but with Android 11?
@RahulPandeyrkp3 жыл бұрын
I haven't tried, but I believe this should work. If not, please LMK and I'll update the repo with the changes.
@re-codee4 жыл бұрын
6:27 is it possible with minSdkVersion 16?
@RahulPandeyrkp4 жыл бұрын
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)
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)
@tomwilliam72992 жыл бұрын
could you please put the github of this code please ? 🙂🙂☺️☺️☺️☺️☺️☺️☺️☺️
@RahulPandeyrkp2 жыл бұрын
github.com/rpandey1234/CameraIntegration
@linqcodmax89653 жыл бұрын
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)
@RahulPandeyrkp3 жыл бұрын
Instead of using
@RahulPandeyrkp3 жыл бұрын
see stackoverflow.com/questions/42516126/fileprovider-illegalargumentexception-failed-to-find-configured-root
@RahulKumar-xr9yq4 жыл бұрын
How to live filter but not with ar
@RahulPandeyrkp4 жыл бұрын
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
@saritagandhi80293 жыл бұрын
How to open the front camera by default?
@RahulPandeyrkp3 жыл бұрын
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.
@RahulPandeyrkp3 жыл бұрын
discussion from SO: stackoverflow.com/questions/19667094/intent-does-not-set-the-camera-parameters/19670928#19670928
@saritagandhi80293 жыл бұрын
@@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.
@Srivatsa2244 жыл бұрын
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
@Srivatsa2244 жыл бұрын
I could find the issues by myself after adding logs. Issue sorted(I had added camera permission in manifest)
@RahulPandeyrkp4 жыл бұрын
@@Srivatsa224 glad you were able to fix it!
@patrickFREE.3 жыл бұрын
how i can save the image ?
@RahulPandeyrkp3 жыл бұрын
it should already be saved in the DCIM directory
@VishalKumar-xm5ue4 жыл бұрын
I m getting error in getExternalFilesDir
@RahulPandeyrkp4 жыл бұрын
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.
@aleks21473 жыл бұрын
startActivityForResult is deprecated, what else can I use?