How to share application link via message share application - android

For my application, I would like to give share option.
For this, I have edit text to give phone number and a share button. If user gives a valid number and clicks share button, list of all available message sending application should list. If user selects an application from the list then a message with the application link should send his phone using the selected application.
How can I implement this? Please help.

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "message link");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Chooser title text"));

try this
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,"your application link"));
startActivity(Intent.createChooser(sharingIntent,"Share using"));

Try Below code,This is exactly that you want ,
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, Your_EditText_object.getText().toString());
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Your Title"));

Try this:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
References link:
https://developer.android.com/training/sharing/send.html

public static void callShare(Context theCtx, String theImagePath, String theText)
{
// Pass the message and Image path that you want to share
File myImageFile = new File(theImagePath);
String shareBody = theText; //"Here is the share content body " ;
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
if (myImageFile.exists()) {
// email address is required to be filled.
sharingIntent.setType("image/jpeg");
// "file://" and .getAbsolutePath is very important for Extra_Stream.
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + myImageFile.getAbsolutePath()));
} else if (!theText.isEmpty()) {
sharingIntent.setType("text/*");
}
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, ""); //"Subject here"
sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
theCtx.startActivity(Intent.createChooser(sharingIntent, "Share via"));
}

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();
}

Send a text message for a specific number using WhatsApp

I'm trying to open WhatsApp with both text message and phone number, the phone number is OK but the message are not being displayed
Here's my code:
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.SetComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.SetType("text/plain");
sendIntent.PutExtra("jid", phone_number + "#s.whatsapp.net");
sendIntent.PutExtra(Intent.ExtraText, "extra_text test");
sendIntent.PutExtra("sms_body", "sms_body test");
sendIntent.PutExtra("body", "body test");
sendIntent.PutExtra("text", "text test");
context.StartActivity(sendIntent);
I've tried all these "PutExtra" options but it's not working.
Thanks in advance!
What they allow via Intent extras is limited.
C# Example:
var sendIntent = new Intent();
sendIntent.SetPackage("com.whatsapp");
sendIntent.SetAction(Intent.ActionSend);
sendIntent.PutExtra(Intent.ExtraText, "StackOverflow.");
sendIntent.SetType("text/plain");
StartActivity(sendIntent);
Ref: https://www.whatsapp.com/faq/android/28000012

Android mail client popup in app? [duplicate]

I am experiecing "This action is not currrently supported" error condition when execute the following code snippet in Android 2.1. What is wrong with the snippet?
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
Uri uri = Uri.parse("mailto:myemail#gmail.com");
intent.setData(uri);
intent.putExtra("subject", "my subject");
intent.putExtra("body", "my message");
startActivity(intent);
}
If you use ACTION_SENDTO, putExtra() does not work to add subject and text to the intent. Use setData() and the Uri tool add subject and text.
This example works for me:
// ACTION_SENDTO filters for email apps (discard bluetooth and others)
String uriText =
"mailto:youremail#gmail.com" +
"?subject=" + Uri.encode("some subject text here") +
"&body=" + Uri.encode("some text here");
Uri uri = Uri.parse(uriText);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(uri);
startActivity(Intent.createChooser(sendIntent, "Send email"));
Actually I found a way where the EXTRAs work.
This is a combination of an answer I found here regarding ACTION_SENDTO
http://www.coderanch.com/t/520651/Android/Mobile/no-application-perform-action-when
and something for HTML which I found here:
How to send HTML email
(but the variant of how to use ACTION_SENDTO in this HTML post didn't work for me - I got the "action not supported" which you are seeing)
// works with blank mailId - user will have to fill in To: field
String mailId="";
// or can work with pre-filled-in To: field
// String mailId="yourmail#gmail.com";
Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto",mailId, null));
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject text here");
// you can use simple text like this
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Body text here");
// or get fancy with HTML like this
emailIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append("<p><b>Some Content</b></p>")
.append("<a>http://www.google.com</a>")
.append("<small><p>More content</p></small>")
.toString())
);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
You Can Try This One
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", emailID, null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT,
Subject);
emailIntent.putExtra(Intent.EXTRA_TEXT,
Text);
startActivity(Intent.createChooser(emailIntent, Choosertitle);
It Works For me

Open Share Dialog to Share a File USing ACTION_SEND

I know how to share A text using ACTION_SEND.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Download Link https://play.google.com/store/apps/details?id=com.mtracker2051");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share This App"));
I want to share a text file using the ShareDialog.
How can I do it.
I read about this here http://developer.android.com/training/sharing/send.html but cound not get much from this link.
String fileName = ...
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("*/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"Share File"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "File Name");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fileName)));
startActivity(Intent.createChooser(emailIntent, "Share File"));

Android: Share plain text using intent (to all messaging apps)

I'm trying to share some text using an intent:
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_TEXT, "TEXT");
and warping with chooser:
startActivity(Intent.createChooser(sms, getResources().getString(R.string.share_using)));
it works! but only for email app.
what I need is a general intent for all messaging app: emails, sms, IM (Whatsapp, Viber, Gmail, SMS...)
tried using android.content.Intent.ACTION_VIEW
and tried using i.setType("vnd.android-dir/mms-sms"); nothing helped...
("vnd.android-dir/mms-sms" shared using sms only!)
Use the code as:
/*Create an ACTION_SEND Intent*/
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
/*This will be the actual content you wish you share.*/
String shareBody = "Here is the share content body";
/*The type of the content is text, obviously.*/
intent.setType("text/plain");
/*Applying information Subject and Body.*/
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
/*Fire!*/
startActivity(Intent.createChooser(intent, getString(R.string.share_using)));
New way of doing this would be using ShareCompat.IntentBuilder like so:
// Create and fire off our Intent in one fell swoop
ShareCompat.IntentBuilder
// getActivity() or activity field if within Fragment
.from(this)
// The text that will be shared
.setText(textToShare)
// most general text sharing MIME type
.setType("text/plain")
.setStream(uriToContentThatMatchesTheArgumentOfSetType)
/*
* [OPTIONAL] Designate a URI to share. Your type that
* is set above will have to match the type of data
* that your designating with this URI. Not sure
* exactly what happens if you don't do that, but
* let's not find out.
*
* For example, to share an image, you'd do the following:
* File imageFile = ...;
* Uri uriToImage = ...; // Convert the File to URI
* Intent shareImage = ShareCompat.IntentBuilder.from(activity)
* .setType("image/png")
* .setStream(uriToImage)
* .getIntent();
*/
.setEmailTo(arrayOfStringEmailAddresses)
.setEmailTo(singleStringEmailAddress)
/*
* [OPTIONAL] Designate the email recipients as an array
* of Strings or a single String
*/
.setEmailTo(arrayOfStringEmailAddresses)
.setEmailTo(singleStringEmailAddress)
/*
* [OPTIONAL] Designate the email addresses that will be
* BCC'd on an email as an array of Strings or a single String
*/
.addEmailBcc(arrayOfStringEmailAddresses)
.addEmailBcc(singleStringEmailAddress)
/*
* The title of the chooser that the system will show
* to allow the user to select an app
*/
.setChooserTitle(yourChooserTitle)
.startChooser();
If you have any more questions about using ShareCompat, I highly recommend this great article from Ian Lake, an Android Developer Advocate at Google, for a more complete breakdown of the API. As you'll notice, I borrowed some of this example from that article.
If that article doesn't answer all of your questions, there is always the Javadoc itself for ShareCompat.IntentBuilder on the Android Developers website. I added more to this example of the API's usage on the basis of clemantiano's comment.
This a great example about share with Intents in Android:
* Share with Intents in Android
//Share text:
Intent intent2 = new Intent(); intent2.setAction(Intent.ACTION_SEND);
intent2.setType("text/plain");
intent2.putExtra(Intent.EXTRA_TEXT, "Your text here" );
startActivity(Intent.createChooser(intent2, "Share via"));
//via Email:
Intent intent2 = new Intent();
intent2.setAction(Intent.ACTION_SEND);
intent2.setType("message/rfc822");
intent2.putExtra(Intent.EXTRA_EMAIL, new String[]{EMAIL1, EMAIL2});
intent2.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
intent2.putExtra(Intent.EXTRA_TEXT, "Your text here" );
startActivity(intent2);
//Share Files:
//Image:
boolean isPNG = (path.toLowerCase().endsWith(".png")) ? true : false;
Intent i = new Intent(Intent.ACTION_SEND);
//Set type of file
if(isPNG)
{
i.setType("image/png");//With png image file or set "image/*" type
}
else
{
i.setType("image/jpeg");
}
Uri imgUri = Uri.fromFile(new File(path));//Absolute Path of image
i.putExtra(Intent.EXTRA_STREAM, imgUri);//Uri of image
startActivity(Intent.createChooser(i, "Share via"));
break;
//APK:
File f = new File(path1);
if(f.exists())
{
Intent intent2 = new Intent();
intent2.setAction(Intent.ACTION_SEND);
intent2.setType("application/vnd.android.package-archive");//APk file type
intent2.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f) );
startActivity(Intent.createChooser(intent2, "Share via"));
}
break;
Use below method, just pass the subject and body as arguments of the
method
public static void shareText(String subject,String body) {
Intent txtIntent = new Intent(android.content.Intent.ACTION_SEND);
txtIntent .setType("text/plain");
txtIntent .putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
txtIntent .putExtra(android.content.Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(txtIntent ,"Share"));
}
Below is the code that works with both the email or messaging app.
If you share through email then the subject and body both are added.
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareString = Html.fromHtml("Medicine Name:" + medicine_name +
"<p>Store Name:" + “store_name “+ "</p>" +
"<p>Store Address:" + “store_address” + "</p>") .toString();
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Medicine Enquiry");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareString);
if (sharingIntent.resolveActivity(context.getPackageManager()) != null)
context.startActivity(Intent.createChooser(sharingIntent, "Share using"));
else {
Toast.makeText(context, "No app found on your phone which can perform this action", Toast.LENGTH_SHORT).show();
}
By Creating an Intent using ACTION_SEND you will be able to put extra its type is Intent.EXTRA_TEXT, the second argument is the text you want to share.
Then by setting the share type as text/plain, the Intent service will bring you all apps that support sharing text
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
Intent shareIntent = Intent.createChooser(sendIntent, null);
startActivity(shareIntent);
Images or binary data:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpg");
Uri uri = Uri.fromFile(new File(getFilesDir(), "foo.jpg"));
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri.toString());
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
or HTML:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/html");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<p>This is the text shared.</p>"));
startActivity(Intent.createChooser(sharingIntent,"Share using"));
Kotlin
Inside the click listener needed to add this module for sharing text via applications like whatsApp, email like Gmail, Slack..
shareOptionClicked.setOnClickListener{
val shareText = Intent(Intent.ACTION_SEND)
shareText.type = "text/plain"
val dataToShare = "Message from my application"
shareText.putExtra(Intent.EXTRA_SUBJECT, "Subject from my application")
shareText.putExtra(Intent.EXTRA_TEXT, dataToShare)
startActivity(Intent.createChooser(shareText, "Share Via"))
}
This code is for sharing through sms
String smsBody="Sms Body";
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", smsBody);
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
100 % Working Code For Gmail Share
Intent intent = new Intent (Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"anyMail#gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Any subject if you want");
intent.setPackage("com.google.android.gm");
if (intent.resolveActivity(getPackageManager())!=null)
startActivity(intent);
else
Toast.makeText(this,"Gmail App is not installed",Toast.LENGTH_SHORT).show();

Categories

Resources