IMPLICIT INTENTS - Android Fundamentals

Поділитися
Вставка
  • Опубліковано 26 лис 2024

КОМЕНТАРІ • 96

  • @d.ndriotis9209
    @d.ndriotis9209 2 роки тому +1

    "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.

  • @rowenarrow
    @rowenarrow 2 роки тому +1

    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.

  • @Harkie_21
    @Harkie_21 Рік тому +1

    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" *

  • @fwajed
    @fwajed 3 роки тому +4

    You can update this segment or add a new segment that uses ActivityResultContracts

  • @dawoodamir2011
    @dawoodamir2011 4 роки тому +3

    Man your content is always good. You deserve more subs 😊

  • @chonglennon343
    @chonglennon343 3 роки тому +3

    I love your tutorials! There are some error caused by deprecated codes. Pls recreate this tutorial with latest code.

  • @matt-g-recovers
    @matt-g-recovers 3 роки тому +1

    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 роки тому +1

      hey I am getting this error can you please help
      'startActivityForResult(Intent!, Int): Unit' is deprecated. Deprecated in Java getting this error

  • @graphicnexus8662
    @graphicnexus8662 Рік тому +1

    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.

  • @MCA_HimanshuSeth
    @MCA_HimanshuSeth 4 роки тому +1

    Very good I want this , this is really very helpful for me

  • @RahmatKhanZai89
    @RahmatKhanZai89 3 роки тому

    You are a great help, @Philipp.

  • @footballCartoon91
    @footballCartoon91 2 роки тому +1

    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

  • @51bpegasi
    @51bpegasi 3 роки тому +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 роки тому +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 роки тому +2

      What worked?

  • @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 ?

  • @michelchaghoury870
    @michelchaghoury870 2 роки тому +3

    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 роки тому +12

      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 роки тому +1

      @@borispuhacin7509 Thank you!

    • @footballCartoon91
      @footballCartoon91 2 роки тому

      @@borispuhacin7509 bro does not work for me

    • @footballCartoon91
      @footballCartoon91 2 роки тому +1

      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?

  • @rehmanullahkhan7389
    @rehmanullahkhan7389 2 роки тому

    Thank you so much. Can you please change to the new function because the two fun are deprecated

  • @sawoodahmed9396
    @sawoodahmed9396 3 роки тому +1

    the explanation is very good but you can record videos with face cam we connect much better

  • @nima7605
    @nima7605 2 роки тому

    Could you make another Implicit Intent tutorial because the android studio does not recommend this method anymore.

  • @mercury1352
    @mercury1352 4 роки тому

    Awesome, man 👍👍 that is so helpful information

  • @footballCartoon91
    @footballCartoon91 2 роки тому +1

    @5:29 Bro activityForResult() is deprecated what should i do?

  • @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 роки тому +2

    awesome dude !

  • @jacobakoto9841
    @jacobakoto9841 3 роки тому +2

    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

  • @alameenda-oh6243
    @alameenda-oh6243 4 роки тому

    Nice video , I have a question. Read image gallery Should we use permission ?

    • @mikec4220
      @mikec4220 3 роки тому

      Yes, you need to put in manifest

  • @aryanvikash1967
    @aryanvikash1967 4 роки тому +1

    Can you please create videos on Retrofit or some Api handling stuffs.. with get Post req

    • @PhilippLackner
      @PhilippLackner  4 роки тому +1

      Tomorrow my next series starts about a clean architecture news app. We will use Retrofit with coroutines there

    • @aryanvikash1967
      @aryanvikash1967 4 роки тому

      @@PhilippLackner ♥️

  • @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 роки тому +2

      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?

  • @TheFlexath
    @TheFlexath 2 роки тому

    Thanks Sir

  • @erkany6753
    @erkany6753 3 роки тому +1

    Awesome! 👍

  • @LarsRyeJeppesen
    @LarsRyeJeppesen 2 роки тому

    Love these

  • @starlite5097
    @starlite5097 4 роки тому +1

    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 роки тому +1

      Ohh no, don't use anything in viewmodels that has something to do with views😅😅 do it in the fragment/activity

    • @starlite5097
      @starlite5097 4 роки тому +1

      @@PhilippLackner so I write the function with intent there, thanks :D

  • @paulndibe250
    @paulndibe250 3 роки тому

    Great content thanks

  • @sanskrutinashikkar7370
    @sanskrutinashikkar7370 Рік тому

    dosn't we need to provide permission for gallery access.

  • @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 роки тому +2

    'startActivityForResult(Intent!, Int): Unit' is deprecated. Deprecated in Java getting this error

    • @michaelkegeles3434
      @michaelkegeles3434 3 роки тому +2

      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 3 роки тому

      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/*")
      }

  • @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 роки тому +1

      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

  • @everythingisforexperience
    @everythingisforexperience 4 роки тому +2

    👍😁

  • @gutic4824
    @gutic4824 4 роки тому

    Nice!!! :)

  • @ajaygalagali5963
    @ajaygalagali5963 4 роки тому

    :) Thanks

  • @Techsultan_
    @Techsultan_ 2 роки тому

    startActivityForResult has been deprecated

  • @alymohamed5966
    @alymohamed5966 2 роки тому +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.

  • @naginipython2772
    @naginipython2772 Рік тому +1

    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)
    }
    }

  • @meirox03
    @meirox03 2 роки тому

    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)