How to send Zip file from sdcard to mail in android - android

Hi friends,
I need to send zip file as attachment to email. I have tried using code below. However, I receive email message without the attachment. What am I doing wrong?
public class MainActivity extends Activity {
Button email;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
email=(Button)findViewById(R.id.button1);
email.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"radha#impressol.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Email Message");
intent.setType("application/zip");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://+/sdcard/zipname.zip"));
startActivity(Intent.createChooser(intent, "Send Email"));
}
});
}
}

In your case remove the "+" from Uri string.
P.S. it'll also work without Uri protocol, like (Environment.getExternalStorageDirectory()+"/zipname.zip");

Related

Sending an email with android not sending one

I am trying to send an email to a user with Android which will include a code. For whatever reason, it does not work.
I have followed this tutorial
What is the problem?
This is the code:
public class PWReset extends AppCompatActivity {
EditText getMail;
Button Continue;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pwreset);
getMail=findViewById(R.id.Mail);
Continue=findViewById(R.id.PWR2);
Continue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String Code = UUID.randomUUID().toString().substring(0, 5);
//After checking if the email is registered in the DB
resetPassword(getMail.getText().toString(), Code);
Intent intent = new Intent(PWReset.this, PWReset2.class);
intent.putExtra("code", Code);
startActivity(intent);
}
});
}
public void resetPassword(String Mail, String code){
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{getMail.getText().toString()});
email.putExtra(Intent.EXTRA_SUBJECT, "Password reset");
email.putExtra(Intent.EXTRA_TEXT, "You have requested a password reset.\nHere is the code for resetting your password:" + code +
"\nIf you have not requested a password reset, ignore this message.");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "gmail"));
}
}

Android Intent (or code) to open email composer in (outlook, gmail)

I would like to know how to open the Activity for composing email in gmail or outlook. By now I only know ho to be redirected to for instance gmail but I would also open the "composer" (or whatever) and add an email address. I've already tried with:
intent.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
but doesnot work
full source to the test-app
public class MainActivity extends AppCompatActivity {
private static final String GOOGLE_MAIL = "com.google.android.gm";
private static final String OUTLOOK = "com.microsoft.office.outlook";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
test(GOOGLE_MAIL);
}
private void test(String mail) {
Intent intent = getPackageManager().getLaunchIntentForPackage(mail);
intent.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
startActivity(intent);
}
}
You can try this:
protected void sendEmail() {
Log.i("Send email", "");
String[] TO = {"someone#gmail.com"};
String[] CC = {"xyz#gmail.com"};
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_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}

Can't add email signature in Android

I'm trying to compose and send an email which will include a signature at the bottom
of my email content in android. I'm able to send an email but I'm not getting the way that allows me to add my own signature. Do you have any suggestion?
here's my code:
public void addListener() {
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
findViewById = (TextView) findViewById(R.id.t1);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL,
new String[] { "some#gmail.com"});
/*i.putExtra(Intent.EXTRA_CC,
new String[] { "some#gmail.com" });*/
i.putExtra(Intent.EXTRA_SUBJECT, "Android Test");
i.putExtra(Intent.EXTRA_TEXT, "Body");
//i.putExtra(Intent.EXTRA_TEXT, "signature");
try {
startActivity(Intent.createChooser(i, "Choose mail app..."));
} catch (android.content.ActivityNotFoundException ex) {
}
}
});
}
I don't think the "signature" is really a different section of an email. I think you can just append your signature to your body.
i.putExtra(Intent.EXTRA_TEXT, "Body" + "\\n" + "Signature");

sending email in android

public class AndroidEmailActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText edittextEmailAddress = (EditText) findViewById(R.id.email_address);
final EditText edittextEmailSubject = (EditText) findViewById(R.id.email_subject);
final EditText edittextEmailText = (EditText) findViewById(R.id.email_text);
Button buttonSendEmail_intent = (Button) findViewById(R.id.sendemail_intent);
buttonSendEmail_intent.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String emailAddress = edittextEmailAddress.getText().toString();
String emailSubject = edittextEmailSubject.getText().toString();
String emailText = edittextEmailText.getText().toString();
String emailAddressList[] = { emailAddress };
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
intent.putExtra(Intent.EXTRA_TEXT, emailText);
startActivity(Intent.createChooser(intent,
"Choice App t send email:"));
}
});
}
}
This is my code.I am not getting any emails.I need to send emails through this intent method.how can I acheive that?Where I went wrong?pls give some suggestions.
I am getting the error when I click the Send email button as "No applications can perform this action."
This is my code to send emails:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.share_email_subject));
sendIntent.setType("message/rfc822");
activity.startActivity(Intent.createChooser(sendIntent, "Choose Email Client"));
Try removing the plain/text type?
It is Good practice to work with original device rather than on Virtual Device. I suggest you try this code block on real device.
Intent sendEmail= new Intent(Intent.ACTION_SEND);
sendEmail.setType("plain/text");
startActivity(Intent.createChooser(sendEmail, "Email:"));
If you want to see more on Email with Intent then refer to this post:
http://androidtutforbeginner.blogspot.com/2012/03/send-email-with-intent-in-android.html

Issue sending mail attachment

I am sending mail through my application mail is sent but the attached text is not sent with it.
public class Email extends Activity {
Button send;
EditText address, subject, emailtext;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.share);
send=(Button) findViewById(R.id.btnsubmitShare);
address=(EditText) findViewById(R.id.edittexttoShare);
subject=(EditText) findViewById(R.id.edittextsubjectShare);
send.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/octet-stream");
// final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());
Email.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
}
}
From this application user can share a link, although mail is sent from it but text is empty
The problem is you are doing
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());
when you should make a call to toString(), so it's going to be:
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText().toString());

Categories

Resources