کد اشتراک گذاری عکس:

Bitmap bitmap;
OutputStream output;

bitmap=BitmapFactory.decodeResource(getResources() ,
com.example.ties.R.drawable.checkerboard_sare);

File filepath=Environment.getExternalStorageDirectory() ;

File dir=new File(filepath.getAbsolutePath()+"/Share_checkerboard/");
dir.mkdir();

final File file=new File(dir, "checkerboard_share");



ImageView iv=(ImageView) findViewById(com.example.ties.R.id.checkerboard_sh are);
iv.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
Bitmap bitmap;
OutputStream output;

// Retrieve the image from the res folder
bitmap = BitmapFactory.decodeResource(getResources(),
com.example.ties.R.drawable.checkerboard_sare);

// Find the SD Card path
File filepath = Environment.getExternalStorageDirectory();

// Create a new folder AndroidBegin in SD Card
File dir = new File(filepath.getAbsolutePath() + "/Share Image/");
dir.mkdirs();

// Create a name for the saved image
File file = new File(dir, "checkerboard.png");

try {

// Share Intent
Intent share = new Intent(Intent.ACTION_SEND);

// Type of file to share
share.setType("image/jpeg");

output = new FileOutputStream(file);

// Compress into png format image from 0% - 100%
bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
output.flush();
output.close();

// Locate the image to Share
Uri uri = Uri.fromFile(file);

// Pass the image into an Intnet
share.putExtra(Intent.EXTRA_STREAM, uri);

// Show the social share chooser list
startActivity(Intent.createChooser(share, "Share Image"));

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return;
}
});
};