Reputation: 43
In android I can not share Images in jpeg as well as in png format. Please help and correct my code
whenever i code for share it gives exception "File format not supported"
This is my code:
Uri imageUri = Uri.parse("android.resource://com.parekh.shareimage/drawable");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "My sample image text");
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
startActivity(shareIntent);
Upvotes: 3
Views: 2159
Reputation: 1608
Store your drawable image into you internal storage and select that image. This way will help you.
try{
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.shareforma);
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File file = new File(extStorageDirectory, "forma.PNG");
FileOutputStream outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
}
catch (IOException e) {
e.printStackTrace();
}
String msgText = "Sample Message";
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/*");
//set your message
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, msgText);
String imagePath = Environment.getExternalStorageDirectory() + File.separator + "image_name.jpg";
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, msgText));
Upvotes: 2