Android Share Intent changing PNG to JPG - android

I'm trying to share an image of type PNG using G-mail. But in mail attachment I'm getting JPG.
final Bitmap selectedRowToBmp = BitmapFactory.decodeResource(getResources(), R.drawable.share_image);
if (selectedRowToBmp != null) {
String pathofBmp = Images.Media.insertImage(hostActivity.getContentResolver(), selectedRowToBmp, null, null);
Uri bmpUri = Uri.parse(pathofBmp);
final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/png");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
}
Any Help will be appreciated.

Related

Sharing an image with some text under it, both in the same message

I am looking to add a text message under an image (not printed on the image) so when I click a share button, the image, and text message to be shared as one message that looks like this:
My code to share an image looks like this:
public void shareImage(View view) {
Intent shareIntent = new Intent();
Uri photoURI = FileProvider.getUriForFile(this, "com.abcd.myapp", theImage);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, photoURI);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Image with ..."));
}
How can I add the text Image created by: abcd.com under the image, (as a text not printed on the image) in the same text message or email etc.
Try this
Uri imgUri = Uri.fromFile(new File(DIRECTORY + "/" + fileName));
//Add this code if you get SecurityException error
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Text you want to attach with image.");
startActivity(Intent.createChooser(shareIntent, "Share Image"));
The following snippet of code should work. We add the image to MediaStore.
public void shareImage(View view) {
Intent shareIntent = new Intent();
shareIntent.putExtra(Intent.EXTRA_TEXT, Constant.SHARE_MESSAGE
+ Constant.SHARE_URL);
Uri photoURI = FileProvider.getUriForFile(this, "com.abcd.myapp", theImage);
Bitmap bm = BitmapFactory.decodeFile(photoURI);
String url= MediaStore.Images.Media.insertImage(this.getContentResolver(), bm, "title", "description");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Image with ..."));
}
A simple case of sharing a bitmap to Twitter/Whatsapp/Facebook Messenger was resolved thanks to #Aniruddh Chandratre solution. MediaStore.Images.Media.insertImage returns a String in content://media format i.e. content://media/external/images/media/610
val savedImageURI = MediaStore.Images.Media.insertImage(
activity.contentResolver, bitmap, "title", "decription")
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(savedImageURI))
shareIntent.type = "image/*"
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
activity.startActivity(Intent.createChooser(shareIntent, "Share Image"))

Share Image in Twitter in Android using Intent

Hello I try to use the share dialog using Intent with the code below. I want to share an image and text at the same time. However I get the eror: Failed to insert image java.io.FileNotFoundException: No such file or directory
My code is as below, am I doing anything wrong. The code is in a fragment class.
Bitmap image = bmResized;
String pathOfBmp = Images.Media.insertImage(getActivity().getContentResolver(), image, "twitter_image.jpg", null);
Uri bmpUri = Uri.parse(pathOfBmp);
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.setAction(Intent.ACTION_SEND);
tweetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
tweetIntent.putExtra(Intent.EXTRA_TEXT, "here is the tweet text");
tweetIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
tweetIntent.setType("image/jpeg");
startActivity(Intent.createChooser(tweetIntent, "Share this via"));
You can look Fabric library. For twitter process usually using Fabric library.
You can look Fabric document:
https://docs.fabric.io/android/twitter/compose-tweets.html
Also this is github link:
https://github.com/fabric/fabric
Try this:
Drawable mDrawable = mImageView.getDrawable();
Bitmap mBitmap = ((BitmapDrawable) mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(getContentResolver(), mBitmap, "Image Description", null);
Uri uri = Uri.parse(path);
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.setType("image/jpeg");
tweetIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(tweetIntent, "Share this via"));

Share surface to other app

I created surface that have grid. After adding on it some objects(circle, photos) I want to share it without grid. Can anyone help me to solve my problem. Here is my code and see my surface with grid attached. surfaceview.
artBoard.setDrawingCacheEnabled(true);
Bitmap b = artBoard.getDrawingCache();
String pathofBmp = MediaStore.Images.Media.insertImage(getContentResolver(), b,"title", null);
Uri bmpUri = Uri.parse(pathofBmp);
final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/png");
startActivity(shareIntent);
artbord is my surfaceview.

Intent share is not able to attach image

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "My text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(http://onman.ir/colorfinder/sample.jpg));
sendIntent.setType("*/*");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(sendIntent, "Share using"));
This code is not able to attach image when sharing intent with Gmail, also it is giving error when sharing with Facebook that share multiple image or a video only. When I change type with sendIntent.setType("image/*") then it is opening the share window of Facebook but with blank text and image.
for sharing you can use this code
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_TEXT,"abc");
shareIntent.putExtra(Intent.EXTRA_STREAM, imagebitmap);
startActivity(Intent.createChooser(shareIntent, "Share using"));
but if you want to do in facebook it will not working through intent you should use facebook sdk to share image and text
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
.setLink(url)
.setCaption(getString(R.string.fb_share))
.setDescription(getString(R.string.fb_share))
.setPicture(
"https://scontent-lhr3-1.xx.fbcdn.net/hphotos-xfp1/v/t1.0-9/11899955_1616850925232395_9146772907853639083_n.jpg?oh=3dd7da7bf03edee84689d66af2024880&oe=56793D62")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
dismissProgressBar();
and in your code you are sharing image url directly first you need to get bitmap then share bitmap instead of url
private void shareImage() {
Intent share = new Intent(Intent.ACTION_SEND);
// If you want to share a png image only, you can do:
// setType("image/png"); OR for jpeg: setType("image/jpeg");
share.setType("image/*");
// Make sure you put example png image named myImage.png in your
// directory
String imagePath = Environment.getExternalStorageDirectory()
+ "/myImage.png";
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Image!"));
Try this code
Please note that when you use the setType() method, you are enabling Android to filter what apps can share your content. For example, you are sharing a text or URL, the appropriate apps to be shown can be Facebook, Messaging or Email. If you are sharing an image, proper apps can be Instagram, Snapped or Picasa.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == UPLOADIMAGE && resultCode == RESULT_OK)
{
uploadImage.setVisibility(View.GONE);
imageView.setVisibility(View.VISIBLE);
if (data !=null)
{
imageUri=data.getData();
imageView.setImageURI(imageUri);
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
columnIndex = cursor.getColumnIndex(filePathColumn[0]);
attachmentFile = cursor.getString(columnIndex);
Log.e("Attachment Path:", attachmentFile);
URI = Uri.parse("file://" + attachmentFile);
cursor.close();
}
else {Toast.makeText(TutorForm.this,"Uploading image failed",Toast.LENGTH_LONG).show();}
}
super.onActivityResult(requestCode, resultCode, data);
OnClickListner
Intent emailIntent=new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"+ clientEmail));
emailIntent.putExtra(Intent.EXTRA_TEXT,body);
emailIntent.putExtra(Intent.EXTRA_SUBJECT,"Tutor Registration from App");
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri uri = Uri.parse(imageUri.toString());
emailIntent.putExtra(Intent.EXTRA_STREAM,URI);
startActivity(Intent.createChooser(emailIntent,"Send Via..."));
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);
Uri uri = Uri.fromFile(imageFileToShare);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
This one work for me
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.share_subject));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.share_message));
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(yourimagepath);
startActivity(Intent.createChooser(shareIntent, "Share Image"));

How to send drawable to twitter intent in android

I have made an android app ,I want to share a drawable to twitter,Currently I have done this way for text,But can any buddy tell me how to attach image to intent to share via twitter ,Thank you in advance,My code is as below:
public void shareTwitterIntent() {
String tweetUrl = "https://twitter.com/intent/tweet?text=3SManiquines";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
Try this (from How to attach a Bitmap when launching ACTION_SEND intent -- perhaps a duplicate?):
String pathofBmp = Images.Media.insertImage(getContentResolver(), bitmap,"title", null);
Uri bmpUri = Uri.parse(pathofBmp);
final Intent emailIntent1 = new Intent( android.content.Intent.ACTION_SEND);
emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent1.putExtra(Intent.EXTRA_STREAM, bmpUri);
emailIntent1.setType("image/png");

Categories

Resources