How can i share text and image in Android - android

I want share my application's content (Text and Image) and for this issue, I wrote below codes:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("*/*");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(content) + "" +"\n\n" + "download us app from this link" + "\n\n" +"https://play.google.com/app/com.example.example");
startActivity(Intent.createChooser(sharingIntent, "select app ..."));
But in this code, I can just share text not sharing image! I want to share Text and Image.
For show Text and Image, I use Webview. I show image into text in webview.
How can I share Text and Image?

Below code is useful to share both text and images with other apps.
String imageToShare = "http://s1.dmcdn.net/hxdt6/x720-qef.jpg"; //Image You wants to share
String title = "Title to share"; //Title you wants to share
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);
shareIntent.setType("*/*");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_TEXT, imageToShare);
startActivity(Intent.createChooser(shareIntent, "Select App to Share Text and Image"));

See below Code,
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_TEXT,"http://lorempixel.com/400/200/sports/1/");//your Image Url
startActivity(Intent.createChooser(intent, "Share Image"));

Add the URI of your image to the bundle (e.g. http://some.server.com/your_image.png), this will allow the same image to be found & used when the data is pulled out of the bundle.

Related

Sharing image thumbnail and text in title like Instagram Shares to WhatsApp Android

I need to share the content to whatsapp as Instagram does in picture attached.
The title section has an thumbnail of the image and title text and link.
Then Message section has a link.
The Message section is straight forward. Any help on implementing the title section will be helpful.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TITLE, "title text");
sendIntent.putExtra(Intent.EXTRA_TEXT, "message section");
sendIntent.setType("text/plain");
startActivity(sendIntent);
I have gone through whatsapp faq but they haven't mentioned list of the labels processed from the intent.
https://faq.whatsapp.com/en/android/28000012
Try below code
Uri imgUri = Uri.parse(pictureFile.getAbsolutePath());
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.setPackage("com.whatsapp");
intent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
intent.putExtra(Intent.EXTRA_STREAM, imgUri);
intent.setType("image/jpeg");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
activity.startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.MakeText(this,"Whatsapp not found",Toast.LENGTH_SHORT).show();
}

How to share image + text on viber / instagram?

On Android I try to share image + text like this :
Uri imageUri = Uri.parse("android.resource://" + getPackageName()
+ "/drawable/" + "ic_launcher");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello");
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
this work fine on Whatsapp (for example) but on viber it's show only the image and skip the text :( On Instagram it's the total opposite, text is send but not the image ...
How can i do ?
Try this for viber :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.viber.voip");
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Message");
Checkout this answer for the Instagram part : https://stackoverflow.com/a/16299999
Hope this helps !!

Android WhatsApp api file(image) + caption

Is some one knows how can i share image or file via my application with text to whatsapp member?
String text = "Look at my`enter code here` awesome picture";
Uri pictureUri = Uri.parse("file://my_picture");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, myPicUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share images..."));
I tried this one and it works great for any file that ends in .txt
It is great, but i just want to add an extra text to this message
Is it possible?

How to post the Image and Text in Facebook using Share Intent

I am using share intent to post the image and text in Social media App. I am using following code
String shareName=advdetails.get(0).getBusinessname();
String description=advdetails.get(0).getDescription();
Uri image = Uri.parse(advdetails.get(0).getBusinesslogo());
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, description);
shareIntent.putExtra(Intent.EXTRA_STREAM, image);
startActivity(Intent.createChooser(shareIntent, shareName));
The above description, image and ShareName are getting from the pojo class.
When I am trying to share these data into Facebook, I am getting the information as "One or more Media items could not be added"
Try this to share image
File filePath = getFileStreamPath("shareimage.jpg");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, _text);
shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(filePath))); //optional//use this when you want to send an image
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));

sharing photo from android app

I have developed one wallpaper application in which I want to add share button to share a photo on whatsapp. Here is my code( but that code is only for any text msg) I want to share a photo.
Please respond with the code where in I can select a wallpaper from my application and send to whatsapp's particular contact.
case R.id.save:
InputStream y11 = getResources().openRawResource(to);
Bitmap b11 = BitmapFactory.decodeStream(y11);
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("image/*");
waIntent.setPackage("com.whatsapp.android");
waIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, to);
startActivity(Intent.createChooser(waIntent, "Share with"));
Replace
waIntent.setType("text/plain");
with
waIntent.setType("image/png");
the package name is wrong. try: com.whatsapp
and this code is to share image via whatsapp
private void shareIt(Uri uri) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/*");
sharingIntent.setPackage("com.whatsapp");
sharingIntent.putExtra(Intent.EXTRA_TEXT,"Shared via my app");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingIntent, "share with"));
}

Categories

Resources