I want to share text in my CardView using share Intent using kotlin but there is a problem with last line in the code in kotlin the code
val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.putExtra(Intent.EXTRA_STREAM, "ali")
shareIntent.type = "text/plain"
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)))
here is the problem in the code
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)))
please help me
see the images to understand me
images
the adapter full code
class MyAdapter(context: Context, listItem: ArrayList<com.EliteTeam.comedytaste.Model.Movie>) : RecyclerView.Adapter<MyAdapter.MyViewHolder>() {
var Context = context
var movieList = listItem;
var layoutInflator = LayoutInflater.from(context)
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MyViewHolder {
var inflateView = layoutInflator.inflate(R.layout.single_item, parent, false)
return MyViewHolder(inflateView)
}
override fun onBindViewHolder(holder: MyViewHolder?, position: Int) {
holder?.moviewTitle?.text = movieList[position].name
holder?.movieDescription!!.text= movieList[position].description
//holder!!.cardImageView!!.background= movieList[position].image
holder?.onclick(Context, position)
holder!!.cardImageView.setBackgroundResource(movieList[position].image)
}
override fun getItemCount(): Int {
return movieList.size
}
class MyViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView) {
var moviewTitle: TextView = itemView?.findViewById(R.id.movieTitleTextView)!!
var movieDescription: TextView = itemView!!.findViewById(R.id.movieDescriptionTextView)
var cardImageView: CardView = itemView!!.findViewById(R.id.imageCard)
var share: ImageButton = itemView!!.findViewById(R.id.share)
fun onclick(context: Context, position: Int) {
cardImageView.setOnClickListener {
}
share.setOnClickListener {
val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.putExtra(Intent.EXTRA_TEXT, "ali")
shareIntent.type = "text/plain"
startActivity(Intent.createChooser(shareIntent,"send to"))
}} }}
You can certainly go to definition of the Start Activity and view the overloads as you are not passing one of the acceptable parameters.
What I like to do, in order to have navigation code all over the place, is to create an IntentFactory like this:
Then you can easily manage using your StartActivity calls with
So if you align the proper parameters you will be good, but I would still recommend extracting it for ease of updating to a factory like this.
Try this :- Use
Intent.EXTRA_STREAM
only when you have to send Binary data like images , if you want to sent text useIntent.EXTRA_TEXT
Just use
Insted of