Adding a Facebook share button on a recycleview

59 views Asked by At

I have added a share button on my layout file and made a clickListeneter for it but still don't know what to do!

@Override
  protected void populateViewHolder(BlogViewHolder viewHolder, Blog model, int position) {
     viewHolder.setDesc(model.getDesc());
     viewHolder.setPostImageUrl(model.getPostImageUrl());
     viewHolder.btnShare.setOnClickListener(new 
     View.OnClickListener() {
        @Override
           public void onClick(View view) {
             ..... 
           }
         });
  }

I updated my code i just need the the image URL, how to get it from recycleview

public void onClick(View view) {
  String pathOfBmp = ..... ;
  Uri bitmapUri = Uri.parse(pathOfBmp);
  Intent sharingIntent = new 
  Intent(android.content.Intent.ACTION_SEND);
  sharingIntent.setType("image/png");
  sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  sharingIntent.putExtra(Intent.EXTRA_STREAM,bitmapUri);
  startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
1

There are 1 answers

4
Muhammad Ashraf On

If you mean that you need to share text on Facebook, you can do the following:

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(sharingIntent, "Share via"));

This will show a dialog that allows you to select whatever app you want to share on.