0

I have tried all the methods, but I cannot get the image from view pager. I got the image current position also. But even though I cannot get the image from the folder.

public class quotes extends AppCompatActivity {

private ShareActionProvider mShareActionProvider;
Button btn;
ViewPager viewPager=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.quotes_pager);
    btn = (Button) this.findViewById(R.id.share);

    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new CustomPagerAdapter(this));

    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("image/jpg");
            int position=viewPager.getCurrentItem();

            Uri uri = Uri.parse("@mipmap-hdpi/"+"apj"+position+".jpg");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
            startActivity(Intent.createChooser(sharingIntent, "Share using"));
        }
    });
}
}

This is my image folder. I kept my images in mip map folder. It makes any problem? If not, please tell me how to get image from that folder using current position of view pager image.

enter image description here

1 Answers1

0

You cannot share image from application asset or resource folder, uri must be accessible for other applications. You need to put image in temporary folder (not app internal folder) then send it via intent. Check this answer.

Alireza Sharifi
  • 1,127
  • 1
  • 9
  • 18