No video

IMPLICIT INTENTS - Android Fundamentals

  Рет қаралды 27,311

Philipp Lackner

Philipp Lackner

Күн бұрын

In this video you will learn what implicit intents are and how we can use them to let the user pick an image from his gallery.
⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:
pl-coding.com/...
Regular Android tutorials on my Instagram: / philipplackner_official
Checkout my GitHub: github.com/phi...

Пікірлер: 96
@d.ndriotis9209
@d.ndriotis9209 2 жыл бұрын
"requestCode" is used in order for the app to differentiate the request that is given. We need to create an if statement in the “onActivityResult” function in order to pass the data to the main activity.
@fwajed
@fwajed 3 жыл бұрын
You can update this segment or add a new segment that uses ActivityResultContracts
@Harkie_21
@Harkie_21 Жыл бұрын
2023 UPDATE: This is what the code should look like using non-depreciated methods: val getContent = registerForActivityResult(GetContent()) { uri: Uri? -> // Handle the returned Uri binding.ivPhoto.setImageURI(uri) } binding.btnTakePhoto.setOnClickListener { getContent.launch("image/*") } I am still learning, so there may be a better way to implement this. This is from my research and what worked for me! * make sure to import "androidx.activity.result.contract.ActivityResultContracts.GetContent" and "android.net.Uri" *
@rowenarrow
@rowenarrow 2 жыл бұрын
Solid video even if though the API has changed a bit and it alters what we will do this video still covers concepts and thought process and it is becoming fun trying to figure out how to adjust the code to replicate the results.
@chonglennon343
@chonglennon343 3 жыл бұрын
I love your tutorials! There are some error caused by deprecated codes. Pls recreate this tutorial with latest code.
@mattgraves3709
@mattgraves3709 3 жыл бұрын
Nicely done, thank you very much. I have always loved the implicit intent system, but I was a little cloudy on how to work with it but not anymore. I feel like I also understand a larger concept here as well so many thanks!
@sahilmakkar2354
@sahilmakkar2354 3 жыл бұрын
hey I am getting this error can you please help 'startActivityForResult(Intent!, Int): Unit' is deprecated. Deprecated in Java getting this error
@dawoodamir2011
@dawoodamir2011 4 жыл бұрын
Man your content is always good. You deserve more subs 😊
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Thanks ❤️
@darwingsanchez5328
@darwingsanchez5328 3 жыл бұрын
I'm a new sub 😎
@51bpegasi
@51bpegasi 3 жыл бұрын
For Android 11, startActivityForResult is deprecated, looking at samples for ActivityResultRegistry but can't seem to get it working for this tutorial. Any help would be appreciated.
@51bpegasi
@51bpegasi 3 жыл бұрын
This seems to work: package com.tutorials.implicitintent import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.activity.result.contract.ActivityResultContracts import com.tutorials.implicitintent.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { lateinit var bindingMain: ActivityMainBinding var getContent = registerForActivityResult( ActivityResultContracts.GetContent()) { bindingMain.ivPhoto.setImageURI(it) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) bindingMain = ActivityMainBinding.inflate(layoutInflater) setContentView(bindingMain.root) bindingMain.btTakePhoto.setOnClickListener { Intent(Intent.ACTION_GET_CONTENT).also { it -> it.type = "image/*" getContent.launch(it.type) } } } }
@vivekharwani
@vivekharwani 3 жыл бұрын
Thank You so much... This Worked for me😊
@ewomer100
@ewomer100 2 жыл бұрын
What worked?
@MCA_HimanshuSeth
@MCA_HimanshuSeth 4 жыл бұрын
Very good I want this , this is really very helpful for me
@graphicnexus8662
@graphicnexus8662 Жыл бұрын
Hi @PhilippLackner ! Thanks for this video. I have a problem, though. startActivityForResult has been deprecated in favor of registerForActivityResult. I'm finding it difficult to transition. Can you please update the video? Thank you!!!
@kitcat2449
@kitcat2449 2 жыл бұрын
Thank you, your teaching style is amazing
@ahmednafiunoman5040
@ahmednafiunoman5040 3 жыл бұрын
You are a very good explainer.
@sawoodahmed9396
@sawoodahmed9396 3 жыл бұрын
the explanation is very good but you can record videos with face cam we connect much better
@rehmanullahkhan7389
@rehmanullahkhan7389 2 жыл бұрын
Thank you so much. Can you please change to the new function because the two fun are deprecated
@RahmatKhanZai89
@RahmatKhanZai89 3 жыл бұрын
You are a great help, @Philipp.
@michelchaghoury870
@michelchaghoury870 2 жыл бұрын
hello Philipp great content, but when i use this code there is deprecation, can you show us how to do it with the update version instead of the deprecated, thank you for your help and support
@borispuhacin7509
@borispuhacin7509 2 жыл бұрын
registerForActivityResult gets it done. This is the whole code: val btnChoseImage: Button = findViewById(R.id.btnChooseImage) val ivImage: ImageView = findViewById(R.id.ivImage) val getImage = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri-> ivImage.setImageURI(uri) } btnChoseImage.setOnClickListener { getImage.launch("image/*") }
@ardrinrexhepi588
@ardrinrexhepi588 2 жыл бұрын
@@borispuhacin7509 Thank you!
@footballCartoon91
@footballCartoon91 2 жыл бұрын
@@borispuhacin7509 bro does not work for me
@footballCartoon91
@footballCartoon91 2 жыл бұрын
uri is actually a nullable Uri object
@footballCartoon91
@footballCartoon91 2 жыл бұрын
how can i go outside of any callback function in general in kotlin for example if the callback that i am in is returning null to one of the parameters Because in this context.. i am trying to implement onActivityResult() callback function which is part of an abstract class ActivityResultLauncher (Because this is the new way i guess) so the function now ask me what i want to do with the uri:Uri? object (i hope you know what i mean here) i want to check if it is null i want it to go out of the callback function i tried to say " if(uri==null) return " but did not work and i try "if(uri==null) return@onActivityResult" because this is recommended by the IDE.. is this the correct way to do?
@footballCartoon91
@footballCartoon91 2 жыл бұрын
First we call " registerForActivityResult()" which then returns an abstract class called "ActivityResultLauncher" which we needs to implement or override inside there are 3 abstract methods that we need to implement/override 1. getContract() //return ActivityResultContract 2. launch(input: I!, options: ActivityOptionsCompat?) // return Unit 3. unregister() //return @MainThread Unit
@darwingsanchez5328
@darwingsanchez5328 3 жыл бұрын
It was so good tutorial, I have a question, in case I need to do the same thing but instead uploading the image to Image View I would to set the activity background ?
@nima7605
@nima7605 2 жыл бұрын
Could you make another Implicit Intent tutorial because the android studio does not recommend this method anymore.
@footballCartoon91
@footballCartoon91 2 жыл бұрын
@5:29 Bro activityForResult() is deprecated what should i do?
@mercury1352
@mercury1352 4 жыл бұрын
Awesome, man 👍👍 that is so helpful information
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Thanks a lot!
@urvishbundela7826
@urvishbundela7826 3 жыл бұрын
Hi sir, you took an example of opening a pdf, can you tell me more about it, how to implement that via implicit intent for PDF reader.
@fuadydheo3155
@fuadydheo3155 4 жыл бұрын
awesome dude !
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Thank you❤️
@erkany6753
@erkany6753 3 жыл бұрын
Awesome! 👍
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Thanks! 👍
@jacobakoto9841
@jacobakoto9841 3 жыл бұрын
That was great! Have a question , whenever I click the button the image doesn't show on the app. ANY HELP
@betaaccount7450
@betaaccount7450 3 жыл бұрын
@Lahty V. you found any solution?
@vikasbhadoriya1466
@vikasbhadoriya1466 3 жыл бұрын
In onActivityResult() if(requestCode ==0){ .... }
@betaaccount7450
@betaaccount7450 3 жыл бұрын
@@vikasbhadoriya1466 yeah I found typo on that line already that was creating the issue
@vikasbhadoriya1466
@vikasbhadoriya1466 3 жыл бұрын
@@betaaccount7450 how far you come up with android development?
@betaaccount7450
@betaaccount7450 3 жыл бұрын
@@vikasbhadoriya1466 actually I completed this series and made an memes app with some libraries and API
@aryanvikash1967
@aryanvikash1967 4 жыл бұрын
Can you please create videos on Retrofit or some Api handling stuffs.. with get Post req
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Tomorrow my next series starts about a clean architecture news app. We will use Retrofit with coroutines there
@aryanvikash1967
@aryanvikash1967 4 жыл бұрын
@@PhilippLackner ♥️
@starlite5097
@starlite5097 4 жыл бұрын
Hello. If I try to implement that button.onClickListener in a function inside a viewmodel of a fragment, I get an error on startActivityForResult. The first parameter it needs is an activity and I don't know how to pass it...
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Ohh no, don't use anything in viewmodels that has something to do with views😅😅 do it in the fragment/activity
@starlite5097
@starlite5097 4 жыл бұрын
@@PhilippLackner so I write the function with intent there, thanks :D
@TheFlexath
@TheFlexath Жыл бұрын
Thanks Sir
@olayiwolaosho4989
@olayiwolaosho4989 3 жыл бұрын
Great content bro Have a question When you click the image in the image Activity how does the intent know it should finish/destroy the image Activity and pass the image clicked to the Main activity ?
@PhilippLackner
@PhilippLackner 3 жыл бұрын
The gallery app is programmed that way. You can declare intent-filters and declare your app as an app that can open images for example
@olayiwolaosho4989
@olayiwolaosho4989 3 жыл бұрын
@Philipp Lackner ohh Now I get it Thanks a lot for your videos really helpful to a lot of people going through their Android development journey !! Really grateful
@sukhwindersingh-lf7bm
@sukhwindersingh-lf7bm 2 жыл бұрын
Hello Philipp, ivPhoto is not working for me. I checked again it look like it is missing from the import library or so. Can you suggest anything?
@alameenda-oh6243
@alameenda-oh6243 3 жыл бұрын
Nice video , I have a question. Read image gallery Should we use permission ?
@mikec4220
@mikec4220 3 жыл бұрын
Yes, you need to put in manifest
@paulndibe250
@paulndibe250 3 жыл бұрын
Great content thanks
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Very welcome
@footballCartoon91
@footballCartoon91 2 жыл бұрын
how can i go outside of any callback function in general in kotlin for example if the callback that i am in is returning null to one of the parameters Because in this context.. i am trying to implement onActivityResult() callback function which is part of an abstract class ActivityResultLauncher (Because this is the new way i guess) so the function now ask me what i want to do with the uri:Uri? object (i hope you know what i mean here) i want to check if it is null i want it to go out of the callback function i tried to say " if(uri==null) return " but did not work and i try "if(uri==null) return@onActivityResult" because this is recommended by the IDE.. is this the correct way to do?
@sahilmakkar2354
@sahilmakkar2354 3 жыл бұрын
'startActivityForResult(Intent!, Int): Unit' is deprecated. Deprecated in Java getting this error
@michaelkegeles3434
@michaelkegeles3434 3 жыл бұрын
this worked for me class MainActivity : AppCompatActivity() { lateinit var btnTakePhoto:Button lateinit var ivPhoto:ImageView val choosePicure=Intent().apply { action=Intent.ACTION_GET_CONTENT type="image/*" } val resultContract=registerForActivityResult(ActivityResultContracts.StartActivityForResult()){ result: ActivityResult?-> if(result?.resultCode==Activity.RESULT_OK){ Log.v("xxx","it was ok") val uri=result.data?.data ivPhoto.setImageURI(uri) } else{ Log.v("xxx","it was not ok")} } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) btnTakePhoto=findViewById(R.id.btnTakePhoto) ivPhoto=findViewById(R.id.ivPhoto) btnTakePhoto.setOnClickListener { resultContract.launch(choosePicure) } } }
@brian_clips
@brian_clips 2 жыл бұрын
I've just watched this video and checked all comments, but still didn't figure out what the problem is. plz help :)
@borispuhacin7509
@borispuhacin7509 2 жыл бұрын
Use registerForActivityResult val btnChoseImage: Button = findViewById(R.id.btnChooseImage) val ivImage: ImageView = findViewById(R.id.ivImage) val getImage = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri-> ivImage.setImageURI(uri) } btnChoseImage.setOnClickListener { getImage.launch("image/*") }
@LarsRyeJeppesen
@LarsRyeJeppesen Жыл бұрын
Love these
@sanskrutinashikkar7370
@sanskrutinashikkar7370 Жыл бұрын
dosn't we need to provide permission for gallery access.
@gopalkrishanbhatnagar6598
@gopalkrishanbhatnagar6598 2 жыл бұрын
This code is not working in Bumblebee Android as ' startActivityForResult' is deprecated. Can you advise on an alternate code in place of the present code so that it runs in Bumblebee also?
@gustavoaugustini9181
@gustavoaugustini9181 2 жыл бұрын
you can use ActivityResultContracts, to know how to use check out the google guide which provides a similar example used in this video: developer.android.com/training/basics/intents/result#launch
@gutic4824
@gutic4824 4 жыл бұрын
Nice!!! :)
@everythingisforexperience
@everythingisforexperience 4 жыл бұрын
👍😁
@ajaygalagali5963
@ajaygalagali5963 4 жыл бұрын
:) Thanks
@Techsultan_
@Techsultan_ 2 жыл бұрын
startActivityForResult has been deprecated
@meirox03
@meirox03 Жыл бұрын
As the code for the intent is now deprecated I was able to do it like this: var ivImage = findViewById(R.id.ivImage) val getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? -> ivImage.setImageURI(uri) } val btnGalery = findViewById(R.id.btnGalery) btnGalery.setOnClickListener { getContent.launch("image/*") }
@Harkie_21
@Harkie_21 Жыл бұрын
You can use binding to access element by ID. For example : binding.ivImage.setImageURI(uri)
@naginipython2772
@naginipython2772 Жыл бұрын
Alright yall, I came up with a solution (as of 2023): val image = findViewById(R.id.[your imageview name]) val content = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> if (result.resultCode == Activity.RESULT_OK) { val data = result.data?.data image.setImageURI(data) } } findViewById(R.id.[your button name]).setOnClickListener { val myIntent = Intent(Intent.ACTION_GET_CONTENT).also { it.type = "image/*" content.launch(it) } }
@DanielTobi00
@DanielTobi00 Жыл бұрын
thanks man.
@alymohamed5966
@alymohamed5966 2 жыл бұрын
startActivityForResult() is deprecated instead you should create an ActivityResultLauncher object using the function registerForActivityResult() with a lambda function that handles the results come from launched activity. Creating a resultLauncher : private val resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {result-> if(result.resultCode == Activity.RESULT_OK){ val data = result.data?.data binding.[YOUR IMAGE VIEW].setImageURI(data) } }
@rowenarrow
@rowenarrow 2 жыл бұрын
I personally just used startActivityIfNeeded(it, 0), but I am saving this to come back to to do the proper way. My way did work though.
TOOLBAR MENUS - Android Fundamentals
11:48
Philipp Lackner
Рет қаралды 35 М.
FRAGMENTS - Android Fundamentals
17:29
Philipp Lackner
Рет қаралды 329 М.
He bought this so I can drive too🥹😭 #tiktok #elsarca
00:22
Elsa Arca
Рет қаралды 43 МЛН
When you discover a family secret
00:59
im_siowei
Рет қаралды 32 МЛН
Zombie Boy Saved My Life 💚
00:29
Alan Chikin Chow
Рет қаралды 33 МЛН
Lecture 21
21:41
IIT KANPUR-NPTEL
Рет қаралды 578
Intents & Intent Filters - Android Basics 2023
25:36
Philipp Lackner
Рет қаралды 71 М.
~/.dotfiles in 100 Seconds
13:54
Fireship
Рет қаралды 417 М.
5 Kotlin Coroutine Secrets I Wish I Knew Earlier
24:23
Philipp Lackner
Рет қаралды 15 М.
CHECKBOX AND RADIOBUTTON - Android Fundamentals
16:01
Philipp Lackner
Рет қаралды 30 М.
BROADCAST RECEIVERS - Android Fundamentals
8:01
Philipp Lackner
Рет қаралды 43 М.
SERVICES - Android Fundamentals
14:16
Philipp Lackner
Рет қаралды 49 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 399 М.
He bought this so I can drive too🥹😭 #tiktok #elsarca
00:22
Elsa Arca
Рет қаралды 43 МЛН