-1

I was working on a Gallery type app. I wanted to add a share option whenever the specific image is tapped but have failed to do so.

I tried to create Intents, It did not work. What should I do?

Here is my Adapter Class code: https://gist.github.com/mukundmadhav/e63fcf7e34414b9b88458400a6d55651

(Also for testing I have saved 8 images in drawable folder)

When I use Intents it shows this error message: Error:(51, 17) error: cannot find symbol method startActivity(Intent)

I have imported the android.content.Intent but the error still persists.

  • I saw your code. it does not have any section for `ShareActionProvider`. read about sharing in android here https://github.com/codepath/android_guides/wiki/Sharing-Content-with-Intents – vipin agrahari Sep 04 '17 at 08:16
  • There is no error. I wanted to know how can I do that. I have no idea. – Peter Stewart Sep 04 '17 at 08:21

1 Answers1

0

try this in adapter :

 viewHolder.img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

        //here write code to share image //get clicked image bitmap and then share
    Bitmap bitmap = ((BitmapDrawable)viewHolder.img.getDrawable()).getBitmap();
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("image/png");
     ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
        String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap , "Title", null);
   // Uri uri = Uri.parse("android.resource://your package 
    //name/"+R.drawable.ic_launcher);
    Uri uri = Uri.parse(path);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello, This is test Sharing");
    startActivity(Intent.createChooser(shareIntent, "Send your image"));

                    }
                });
Bapusaheb Shinde
  • 839
  • 2
  • 13
  • 16