I have a problem that I want in my application to have a specific email receiver whenever the user press the email button it shows to him/her a fixed receiver. How can I do this?
public void google(View v){
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
Intent shareIntent = Intent.createChooser(emailIntent,"");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(shareIntent);
}
this is the code
this is the image of email
Use this code hope it will help
Intent Email = new Intent(Intent.ACTION_SEND);
String[] recipents ={"your_recepient_email"};
Email.putExtra(Intent.EXTRA_EMAIL,recipents);
Email.setType("text/html")
Email.setPackage("com.google.android.gm");
startActivity(Intent.createChooser(Email, "Send mail"));
If you want subject and content use the code like how you added the lines for subject.
Related
Im trying to send an email from my Android app. With the click of a button, gmail should open and show a new email with my previously defined recipient, subject and email body.
This was how it was working for 2 days but today, the recipient address is not getting copied to the gmail address bar -- only subject and body are getting copied.
this is my code (i havent changed it -- its the same as it was 2 days back):
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, recipient);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
Add recipient address in String Array,:
Try this code:
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{recipient});
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
I am sending email using intent but the subject and message body is not being set.
Intent sendMail = new Intent(Intent.ACTION_SEND);
sendMail.setType("*/*");
sendMail.setType("message/html");
sendMail.setPackage("com.google.android.gm");
sendMail.putExtra(Intent.EXTRA_EMAIL , email);
sendMail.putExtra(Intent.EXTRA_SUBJECT , subject);
sendMail.putExtra(Intent.EXTRA_TEXT , message);
startActivity(Intent.createChooser(sendMail , "Choose an Email Client"));
I also faced this problem. Be clear that those string values are not null. You could also use ACTION.SENDTO. Use the below code; it worked for me.
Intent sendMail = new Intent(Intent.ACTION_SENDTO);
sendMail.setData(Uri.parse("mailto:"));
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.setSelector( sendMail );
startActivity(Intent.createChooser(intent, "Choose an Email Client"));
I'm trying to make this program that when the user clicks a button, a message is sent to a whatsapp number
Here is the code in the onClick method
Uri uri = Uri.parse("smsto:" + "xxxxxxxxxx"); //xxx.. is the mobile number
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, "Check");
i.setType("text/plain");
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
It shows that there are no apps that can perform this action. Why?
I removed
i.setType("text/plain");
And it works. But the text "Check" is not sent. How to do that if this is not the way.
Your format is slightly different from the example given on the WhatsApp FAQ, so I would modify to match.
From this page:
Like most social apps on Android, WhatsApp listens to intents to share media and text. Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker:
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(sendIntent);
However, if you prefer to share directly to WhatsApp and bypass the system picker, you can do so by using setPackage in your intent:
sendIntent.setPackage("com.whatsapp");
This would simply be set right before you call startActivity(sendIntent);
Try this code to send ON whatsapp
public void SendWhatsapp(View view) {
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
I am practising by making an app in which the user can send a WhatsApp message to a particular person .I tried some code snippets which i found on internet but whenever i try to send a WhatsApp msg from an actual device, i am gettig an error "No Application can perform this action".
Here is my code:-
public void sendMessage(View v) {
try
{
String whatsAppMessage = message.getText().toString();
Uri uri = Uri.parse("smsto:" + "9888873438");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
i.setType("text/plain");
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
}catch (Exception e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show();
}
}
Please help .
You receive no application can perform this action because you should remove i.setType("text/plain"); from your code:
String whatsAppMessage = message.getText().toString();
Uri uri = Uri.parse("smsto:" + "9888873438");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
Unfortunately as you can see WhatsApp now opens in the conversation activity but there isn't the text you set in the Intent. This is because WhatsApp doesn't support this kind of share. The only supported share with Intent is ACTION_SEND as you can see in the WhatsApp FAQ:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
I am new to Android application development and with very little java knowledge. I want to call the default Android email application from my application once a button is clicked. What code should i use ?
Thanks And Regards.
You can create an email intent for that:
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"address#domain.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Some Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Some body");
context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
In Android, you launch other activities by sending an intent to the android OS. The OS will then determine what activities subscribe to the intent, and either use a default or allow the user to select one. Use the following intent to just launch email:
Intent email = new Intent(android.content.Intent.ACTION_SEND)
You can also include a default subject, to field, content, etc by using the bundle on the intent. There is a great tutorial here
try this code
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("plain/text");
sendIntent.setData(Uri.parse("demoemail#gmail.com"));
sendIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "demoemail#gmail.com" });
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "demo of email");
sendIntent.putExtra(Intent.EXTRA_TEXT, "hi my message");
startActivity(sendIntent);