I want the user to be able to send an email from inside my android app, so I have
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,message);
startActivity(emailIntent);
but I don't know what I need to do if I want to have 2 .png images attached to this email also.
Thanks,
Try out this one.
But for me it is only working on a real device.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
emailIntent.setType("image/png");
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file1));
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file2));
emailIntent.putExtra(Intent.EXTRA_STREAM, uris));
startActivity(emailIntent);
Try this:
Intent iShare;
iShare = new Intent(Intent.ACTION_SEND);
iShare.setType("image/png");
//below you trying to send the images path it always doens have to be a
//image in the drawable u can get the captured image or in the gallery :)
iShare.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fn.getPath()));
i.putExtra(Intent.EXTRA_TEXT, "Username: " + usernames + "\nClinic Number: " + clnumber + "\nClinic Name: " + clname + "\nBranch: " + spnnr);
startActivity(Intent.createChooser(iShare, "Share"));
try {
startActivity(Intent.createChooser(ishare, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(secondpage.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Related
I am using an image and text to share in whatsapp and other email and sms through intent.
But problem in whatsapp is, image is displaying, text too displaying but url is not displaying as link. It's displaying as normal text. You can see the below code as follows.
Uri imageUri = Uri.parse(photoFile.getAbsolutePath()); //getting image
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
//Target whatsapp:
shareIntent.setPackage("com.whatsapp");
//Add text and then Image URI
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Sharing the details.\n\n" +
"QR Code:" + QRCode + "\n" +
"Nama Retailer:" + retailerName + "\n" +
"Nama Owner:" + ownerName + "\n" +
"Nomer TRX:" + normorTrx + "\n" +
"Disclaimer" + "\n" +
"Please use the below link" + " "+
"http://116.12.2/images/disclaimer/NG20_SaTria_TC_Legal_050418_DISCLAIMER.pdf" +" "+
"for further information."
);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
if (shareIntent.resolveActivity(getPackageManager()) != null) {
startActivity(shareIntent);
} else {
Toast.makeText(RetailerQRCodeGenerationActivity.this, "not available", Toast.LENGTH_SHORT).show();
}
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(RetailerQRCodeGenerationActivity.this, "Application not available.", Toast.LENGTH_SHORT).show();
}
When you want to share a url you generally do this:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
i=intent.putExtra(Intent.EXTRA_TEXT, "http://www.url.com");
But you want to share two different type of intents, because I am seeing in your code that you are using shareIntent.setType("image/jpeg");
Two share different types of elements you need to use multiple MIME types like this:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
String[] mimeTypes = {"image/*", "text/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
For more details check: https://developer.android.com/guide/topics/providers/content-provider-basics#MIMETypeReference
I am trying to attach a text file in order to send it with an email
but whenever i open the Email app it says that the file does not exist Help Please
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"musabyahya1005#gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse(directory+"/data.txt"));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getBaseContext(), "An Error Happened ", Toast.LENGTH_SHORT).show();
}
If you are trying to send files with email, make sure that they are on a public accessible location and that you tell it that it is a file you want to send. Use this code as an example.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("message/rfc822").putExtra(Intent.EXTRA_EMAIL, new String[]{"fake#example.com"}).putExtra(android.content.Intent.EXTRA_SUBJECT, "Mail subject").putExtra(android.content.Intent.EXTRA_TEXT, "lalalala");
String targetFilePath = Environment.getExternalStorageDirectory().getPath() + File.separator + "tmp" + File.separator + "test.txt";
Uri attachmentUri = Uri.parse(targetFilePath);
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://" + attachmentUri));
i want to send .apk file from sdcard via email intent but not getting attachment.
see below codei try this code but not working for me..
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "email id" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"go on read the emails");
Log.v(getClass().getSimpleName(),
"sPhotoUri=" + Uri.parse("file:/" + "/sdcard/obb/rr.apk"));
emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file:/" + "/sdcard/obb/rr.apk"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
This code says could not attachment and not getting mail.
Try to change the type of your attachment as below:
emailIntent.setType("application/zip");
thanks for help i got the mail using this one.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("*/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"email id"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App new 1");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/rr.apk"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Don't use hard coded /sdcard/ there is no guarantee that the SD card will have that path
Instead change
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/" + "/sdcard/obb/rr.apk"));
to
Uri fileUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separatorChar + "obb" + File.separatorChar + "rr.apk"));
emailIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
Also change
emailIntent.setType("text/plain");
to
emailIntent.setType("application/zip");
I want to attach amr file in attachment but i am unable to attach.
My code is as follows:
Intent emailIntent = new Intent(
Intent.ACTION_SEND);
Uri U = Uri.parse(path of amr file);
//System.out.println("uri is:" + U);
emailIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { "" });
emailIntent.putExtra(
android.content.Intent.EXTRA_SUBJECT,
" from ..");
emailIntent.putExtra(
android.content.Intent.EXTRA_TEXT, ""
+ "\n" + "\n" + "Through application name");
emailIntent.setType("audio/rfc822");
//emailIntent.setType("audio/*");
// emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,U);
emailIntent.putExtra(Intent.EXTRA_STREAM, U);
startActivity(Intent.createChooser(emailIntent,
""));
i have used emailIntent.setType("audio/rfc822") , emailIntent.setType("audio/*"); and emailIntent.setType("audio/amr"); but no luck
Any help will be appreciated.
have you tried using,
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
Activity Action: Deliver multiple data to someone else.
I have loaded images from drawable folder into the image switcher. And I have placed a button in that activity. So if I click that button means, the current image in switcher should be mailed using intent's action_send.
find which drawable is currently set and then
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.your file);
intent.setType("image/png");
to send multiple images
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
emailIntent.setType("image/png");
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file1));
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file2));
emailIntent.putExtra(Intent.EXTRA_STREAM, uris));
startActivity(emailIntent);