Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share Bitmap() on android to twitter, facebook, mail

maybe an easy question: I want to share a bitmap I received over the net to twitter/facebook/etc with the default share "intent".

The code I found

        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setType("image/jpeg");
        sendIntent.putExtra(Intent.EXTRA_STREAM, "IDONTKNOW");
        sendIntent.putExtra(Intent.EXTRA_TEXT,
                "See my captured picture - wow :)");
        startActivity(Intent.createChooser(sendIntent, "share"));

needs to be filled at the point "IDONTKNOW" with the bitmap. (this.bitmap)

I found no way to handle this without saving the bitmap to internal sd..

regards

like image 859
chrstnwhlrt Avatar asked Apr 05 '11 16:04

chrstnwhlrt


Video Answer


1 Answers

Simply, you can convert a bitmap into PNG from external storage.

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File imageFile = new File(path, getCurrentTime()+ ".png");
FileOutputStream fileOutPutStream = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.PNG, 80, fileOutPutStream);

fileOutPutStream.flush();
fileOutPutStream.close();

Then, you can get a URI through Uri.parse:

return Uri.parse("file://" + imageFile.getAbsolutePath());
like image 121
feelinglucky Avatar answered Sep 29 '22 20:09

feelinglucky