[英]sending email in android app
因此,我试图做到这一点,即当用户兑现奖品时,他必须向我发送他的电子邮件以及他兑现的金额。 这是我到目前为止的代码...这是我的xml文件。
<Button
tools:ignore="HardcodedText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="$1 (100K)"
android:drawableLeft="@drawable/amazon"
android:drawableStart="@drawable/amazon"
android:id="@+id/button7"
android:textSize="35sp"
android:layout_gravity="center_horizontal" />
这是我的activity.java
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class AmazonActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.amazon_layout);
Button mEmail = (Button) findViewById(R.id.button7);
mEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// open email client using intent
Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto", "pepsiass666@gmail.com",null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Welcome To My App");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body Of Email");
startActivity(Intent.createChooser(emailIntent, "Send Email"));
}
});
}
}
运行我的应用程序后,当我单击该按钮时,它说明它不受支持。 有人知道我在想什么吗?
使用.setType(“ message / rfc822”)和try-catch块以避免错误
mEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] emails = {"pepsiass666@gmail.com"};
String subject = "Welcome To My App";
String message = "Body Of Email";
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, emails);
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
// need this to prompts email client only
email.setType("message/rfc822");
try
{
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "No Email application", Toast.LENGTH_SHORT).show();
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.