Reputation: 482
I am developing the android application for the ready-made shop. what they want is, when the customer shares the full catalog, all the items in the catalogs (Say about 10 items) should be shared via whats app or Facebook.. I know the code for string part once the image is loaded on the image-view. But here i have just the URL of all the items from database, and how can i share those images on Whats app or Facebook..??
This is the code, i am using for sharing single image that is already loaded on image-view
String abc = "hi";
Uri bmpUri = getLocalBitmapUri(image);
if (bmpUri != null)
{
// Construct a ShareIntent with link to image
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.putExtra(Intent.EXTRA_TEXT, abc);
shareIntent.setType("image/*");
// Launch sharing dialog for image
context.startActivity(Intent.createChooser(shareIntent, "Share Image"));
}
else
{
Toast.makeText(context, "No Image..",Toast.LENGTH_SHORT).show();
// ...sharing failed, handle error
}
And this is the function that is used above..
public Uri getLocalBitmapUri(ImageView imageView)
{
// Extract Bitmap from ImageView drawable
Drawable drawable = imageView.getDrawable();
Bitmap bmp = null;
if (drawable instanceof BitmapDrawable)
{
bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
}
else
{
return null;
}
// Store image to default external storage directory
Uri bmpUri = null;
try
{
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png");
file.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
bmpUri = Uri.fromFile(file);
}
catch (IOException e)
{
e.printStackTrace();
}
return bmpUri;
}
Any Help Please.. Thank You in advance..
Upvotes: 0
Views: 100
Reputation: 808
If you have the original URL handy, that would be the easiest route to go for a single image.
But if you're going to be doing multiple images, then you'll want to look at the Facebook SDK and post them using the Open Graph API. https://developers.facebook.com/docs/graph-api/reference/page/photos/
Upvotes: 1