Share Text, Images, Multiple Images Using Kotlin

Intent 


Intent object provides us many functionalities
  1. Starting another activity  (eg., Login activity to MainActivity)
  2. Starting background service(eg., Download large files that run on background)
  3. Sending a Broadcast (eg., Firebase Messages to any alive activity)

Intent types

      Explicit Intent

           Calling fully qualified targets like starting another activity within an app or starting a download progress by calling a service


      Implicit Intent


           It's like sharing a content or to ask another application to perform certain actions eg., opening a browser, opening images, playing a video by choosing player like MX player or vlc player or default Videos player


Share Text

val sendIntent = Intent()
sendIntent.action = Intent.ACTION_SEND
sendIntent.type = "text/plain"
sendIntent.putExtra(Intent.EXTRA_TEXT, "http://google.com/careers")
startActivity(Intent.createChooser(sendIntent, "send to "))

Share Image

val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.type = "image/jpeg"
shareIntent.putExtra(Intent.EXTRA_STREAM,Utitlities.geturi("apple",this))
startActivity(Intent.createChooser(shareIntent, ""))



Share Multiple Images


val imageUris = ArrayList<Uri>()
imageUris.add(Utitlities.geturi("android", this)) // Add your image URIs here
imageUris.add(Utitlities.geturi("windows", this))
imageUris.add(Utitlities.geturi("apple", this))

val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND_MULTIPLE
shareIntent.type = "image/*"
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris)
startActivity(Intent.createChooser(shareIntent, "Share images to "))

Explanation

  1. Creating an intent object
  2. Setting what intent want to do
  3. Setting share types like image or video or text
  4. Data to share
  5. Start a share



GitHub: https://goo.gl/ZA7hAQ




val sendIntent = Intent()
sendIntent.action = Intent.ACTION_SEND
sendIntent.putExtra(Intent.EXTRA_TEXT, "http://google.com/careers")
sendIntent.type = "text/plain"
startActivity(Intent.createChooser(sendIntent, "send to "))




Comments

Popular posts from this blog

GESTURE DETECTOR ON VIEWS | IMAGEVIEW | TEXTVIEW | BUTTON | RELATIVELAYOUT

ButterKnife with Kotlin