mardi 19 mai 2015

Start ACTION_SEND Intent from Library

I want to start an intent for sending email with clients. But context.startActivity does not work in library project. Can you help me? Thanks

public class email {
private Context context;

public email(Context context) {
    this.context = context;
}

public void send(String to, String subject, String body) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_EMAIL, to);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, body);

    try {
        context.startActivity(Intent.createChooser(intent, "sending..."));
    }
    catch (ActivityNotFoundException e) {

    }
}

Aucun commentaire:

Enregistrer un commentaire