1

I've inserted share button on my Gif image application and it work perfectly fine but I have a problem to do coding for share image using the share button.

This is my code in Main Activity:

GridView gridView;
private int[] gifImages = {R.drawable.pb_1, R.drawable.pb_2, R.drawable.pb_3, R.drawable.pb_4, R.drawable.pb_5, R.drawable.pb_6, ....);

and this is my code in GridItemActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_grid_item);

    image = findViewById(R.id.imageView);

    Intent intent = getIntent();
    image.setImageResource(intent.getIntExtra("image", 0));
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);
    return super.onCreateOptionsMenu(menu);

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

        case R.id.share_button:
            Uri mImageUri = Uri.parse(getResources().getDrawable(R.drawable.pb_1).toString());
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("image/gif");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, mImageUri);
            startActivity(Intent.createChooser(sharingIntent, "Share Using"));
            break;
    }

    return super.onOptionsItemSelected(item);
}

}

Unfortunately it doesnt work...

Can anyone please help me?

ADM
  • 20,406
  • 11
  • 52
  • 83
Zee
  • 11
  • 1
  • 2
  • Possible duplicate of [Sharing a png image in drawable folder](https://stackoverflow.com/questions/18502598/sharing-a-png-image-in-drawable-folder) – ADM Jul 10 '19 at 04:25
  • You have to save image in the storage first .. go through the above link or similar .. reason is drawable folder of your app is not exposed to Other Applications .. – ADM Jul 10 '19 at 04:26
  • Hi thanks ! I have follow the guidelines however where can I get "uriToImage in sharingIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);?" – Zee Jul 10 '19 at 05:41

1 Answers1

0

check is https://developer.android.com/training/sharing/send

Read the following Topics of this documentation

  • Send binary content
  • Send multiple pieces of content
damith alahakoon
  • 270
  • 4
  • 14
  • Hi thanks ! I have follow the guidelines however where can I get "uriToImage in sharingIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);?" – Zee Jul 10 '19 at 05:40