i have a document which is loaded in webViewActivity, in this document i have my email id. when users clicks my email id i want to open email app, please help me.
This is sample document.
This is text contained in document. if you have any queries please contact me at mailto#examplemail.com
Try this :
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//Check whether url contains email or not.
// To start Email Intent
String[] mailto = { "example.com" };
// Create a new Intent to send messages
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Add attributes to the intent
sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "This is sample document.");
sendIntent.setType("message/rfc822");
startActivity(sendIntent);
return true;
}
Hope this helps.
Related
I have a webview from which user can share a link to whatsapp but i want that when ever user share a link via whatsapp from webview my app name should also be sent in that text file . webview is in fragment
i want that my app name should be displayed in captions section "say something " and same on whats app or any other social media
i have tried
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
boolean overrideUrlLoading = false;
if (url != null && url.startsWith("whatsapp://")) {
Intent text = new Intent();
Intent text1 = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
text.setAction("android.intent.action.SEND");
text.setType("text/plain");
text.putExtra("android.intent.extra.TEXT", "my app name ");
startActivity(text);
startActivity(text1);
}
and this too
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
boolean overrideUrlLoading = false;
if (url != null && url.startsWith("whatsapp://")) {
Intent text1 = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(text1);
Intent text = new Intent();
text.setAction("android.intent.action.SEND");
text.setType("text/plain");
text.putExtra("android.intent.extra.TEXT", "my app name ");
startActivity(text);
}
i want to send my app name with the link (from webview) just like sharechat . any help ??
my app just send the link but it dont send my app name with that link
#anshul raj ///use this code its working properly
private void shareApp() {
String appName = getString(R.string.app_name);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
String shareBodyText = "https://stackoverflow.com/questions/4969217/share-application-link-in-android"+"\n"+appName;
shareIntent.putExtra(Intent.EXTRA_TEXT, shareBodyText);
startActivity(Intent.createChooser(shareIntent,getString(R.string.app_name)));
}
Try below code
text.putExtra("android.intent.extra.TEXT", getString(R.string.appname);
You can pass app name from string file.
Use the below code to share text to WhatsApp
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "my app name");
intent.setType("text/plain");
intent.setPackage("com.whatsapp");
startActivity(intent);
//postURL- this is URL of an article from a blog which I want to post on my facebook feed.
public void setupFacebookShareIntent(String postURL) {
ShareDialog shareDialog;
FacebookSdk.sdkInitialize(getApplicationContext());
shareDialog = new ShareDialog(DetailedActivity.this);
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse(postURL))
.build();
shareDialog.show(linkContent);
}
Is it possible to send an email, using an intent, with an image in the body.
I'm using an image that is hosted...
public void sendEmail(View view){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_SUBJECT, "Image in body test");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(getHtmlBody()));
startActivity(Intent.createChooser(intent, "Send Email"));
}
private String getHtmlBody() {
String html = "<h1><img width=\"100\" src=\"http://cdn2-www.dogtime.com/assets/uploads/gallery/30-impossibly-cute-puppies/impossibly-cute-puppy-8.jpg\"> Hello World </h1>";
return html;
}
I am able to do this using javaMail but that sends the email automatically without the user being able to see anything so I'm hoping I can use intents.
There is EXTRA_HTML_TEXT that allows you to supply HTML as alternative to the text in EXTRA_TEXT. However, there's no guarantee that the receiving app supports this extra (hence the requirement that EXTRA_TEXT must be present, too).
The code could look something like this:
public void sendEmail(View view){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Image in body test");
intent.putExtra(Intent.EXTRA_TEXT, getTextBody());
intent.putExtra(Intent.EXTRA_HTML_TEXT, getHtmlBody());
startActivity(Intent.createChooser(intent, "Send Email"));
}
private String getHtmlBody() {
return "<h1><img width=\"100\" src=\"http://cdn2-www.dogtime.com/assets/uploads/gallery/30-impossibly-cute-puppies/impossibly-cute-puppy-8.jpg\">"
+ getTextBody() + "</h1>";
}
private String getTextBody() {
return "Hello world";
}
Apps that don't support HTML will simply use the text from EXTRA_TEXT.
The answer by Arpit Garg in this post shares that and tags do not work in most email clients, so unfortunately your code wont work. I just tested your code with the Gmail app and a few others and it pulled in a placeholder but not the actual image. what you can do though is add an image as an attachment.
I am trying to create application and the application will able to send email from the application from WebView android. the example of the code will be like
Send Email
the code working fine in browser, but in the WebView in android itself, it shown that the action is not supported.So I wonder, is it possible to send an email using HTML only in WebView?
Something like this will do the job in your webview client.
What it does :
First, parse the link, to detect if it's an mailto link or not.
Parse to get the arguments of the mailto link
Send the email in an intent, with the given argument of your mailto link
See below :
public boolean shouldOverrideUrlLoading (WebView view, String url){
String mailToRegexp = "mailto\\:([^?]+)\\?{0,1}((subject\\=([^&]+))|(body\\=([^&]+))|(bcc\\=([^&]+))|(cc\\=([^&]+)))*";
Pattern mailToPattern = Pattern.compile(mailToRegexp);
Matcher mailToMatcher = mailToPattern.matcher(url);
if(mailToMatcher.find()){
String email = mailToMatcher.group(1);
String subject = mailToMatcher.group(4);
String body = mailToMatcher.group(6);
String bcc = mailToMatcher.group(8);
String cc = mailToMatcher.group(10);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, email);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, body);
intent.putExtra(Intent.EXTRA_BCC, bcc);
intent.putExtra(Intent.EXTRA_CC, cc);
startActivity(Intent.createChooser(intent, "Send Email"));
return true;
}
}
You will need to override (in your webview class) shouldOverrideUrlLoading (http://developer.android.com/reference/android/webkit/WebViewClient.html#shouldOverrideUrlLoading(android.webkit.WebView,%20java.lang.String)) to parse mailto links and send intent to mail app.
If you are using cordova/phonegap, you need to import inAppBrowser plugin and add target="_system" to your links so they will get directed as an intent
Well, im trying to make my app sending an email with infromation entered in the entry text elements, but when I try it in the phone it says "No application can perform this action. Here is my code. Thank you.
View boton = (Button) findViewById(R.id.enviar);
boton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if (v.getId()==findViewById(R.id.enviar).getId())
{
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String mailId= "villasantdesign#gmail.com";
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{mailId});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Consulta Técnica");
emailIntent.putExtra(Intent.EXTRA_TEXT, etlugar.getText()); etfecha.getText(); etcable.getText(); etqe.getText(); etantena.getText(); etampli.getText(); etmodulo.getText();}{
startActivity(Intent.createChooser(emailIntent, "Envío"));
}}}
You just need to configure an email account in your default Email application or in any other email clients like Gmail,so that It can redirect the user to that application and let him send the email.
Solution:
The below snippet works absolutely fine.
View boton = (Button) findViewById(R.id.enviar);
boton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if (v.getId()==findViewById(R.id.enviar).getId())
{
Intent emailIntent = new Intent(Intent.ACTION_SEND, Uri.fromParts("mailto","villasantdesign#gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Consulta Técnica");
emailIntent.putExtra(Intent.EXTRA_TEXT, etlugar.getText());
startActivity(Intent.createChooser(emailIntent, "Envío"));
}}}
I hope it will be helpful !!
I think you have to install Email App to you phone, like Gmail, or Android can not find any App to receive that intent. And you should change Intent.ACTION_SEND to Intent.ACTION_SENDTO
Try setting up mime-type:
emailIntent.setType("text/plain");
& change android.content.Intent.ACTION_SENDTO instead of Intent.ACTION_SENDTO to get only the list of e-mail clients, with no facebook or other apps. Just the email clients.
You need to configure an email account in your default Email application.
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("plain/text");
email.putExtra(Intent.EXTRA_EMAIL,
new String[] { abc#gmail.com) });
email.putExtra(Intent.EXTRA_SUBJECT, "");
email.putExtra(Intent.EXTRA_TEXT,"");
startActivity(Intent.createChooser(email,
"Choose an Email client :"));
android.content.Intent.ACTION_SEND intent is the mail sending intent.Intent.createChooser(emailIntent, "Envío") will going to prompt you to select the mail sending application from the collection of configured sending applications like Gmail App. if no mail is configured in your device or simulator it will reply like no app can perform this action.
I have been working with Java and Xml for a few months now, and have learned a great deal thanks to everyones help on StackOverflow.
My question is about java programming for android in relation to the submit button.
Currently I am trying to figure out how to submit a value to an email address (behind the scenes)
Lets say we have a text field and a button; I want to take the value entered in the text field, and submit that to an email address onclick.
I am unable to find anything online that shows me how to do this.
Thank you in advance for reading through my post and I look forward to your suggestions.
This is a great example of how using Intents can come in great handy!
Android has a bunch of pre-defined Intents that do certain things within the system; you may have clicked on a picture before and a dialog popped up asking whether you would like to view it in your gallery or in a third-party app such as Astro. The viewing of an image has its own pre-determined intent.
Sending an email also has its own pre-determined intent: android.content.Intent.ACTION_SEND. You'll need to create an intent with that property and then attach extra information (ie. the address to send to, the subject/message body, etc.).
Example code:
// Data members
private Intent emailIntent;
private String feedback;
private EditText feedbackBox;
// Create the Intent, and give it the pre-defined value
// that the Android machine automatically associates with
// sending an email.
emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
// Put extra information into the Intent, including the email address
// that you wish to send to, and any subject (optional, of course).
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"your_email#whatever.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Insert subject here");
// Acquire feedback from an EditText and save it to a String.
feedback = feedbackBox.getText().toString();
// Put the message into the Intent as more extra information,
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, feedback);
// Start the Intent, which will launch the user's email
// app (make sure you save any necessary information in YOUR app
// in your onPause() method, as launching the email Intent will
// pause your app). This will create what I discussed above - a
// popup box that the user can use to determine which app they would like
// to use in order to send the email.
startActivity(Intent.createChooser(emailIntent, "Insert title for dialog box."));
I hoped this helped!!
Some sources you might like to check out:
http://developer.android.com/guide/topics/intents/intents-filters.html
http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, someEditText.getText());
startActivity(Intent.createChooser(emailIntent, "Send someone an email..."));
try this
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:Type email address here"));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
It works good
String mail=mailid.getText().toString();
String msubject=subject.getText().toString();
String mbody=body.getText().toString();
Log.i("Send email", "");
String[] TO = {mail};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Static subject "+ msubject);
emailIntent.putExtra(Intent.EXTRA_TEXT, "Static body "+ mbody);
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}