Android 如何在电子邮件活动中设置“收件人”文本区域的文本
我做了一个活动 在“订阅”按钮上,我必须向一些默认电子邮件发送电子邮件,我的代码为: 软件包sditm.appAndroid 如何在电子邮件活动中设置“收件人”文本区域的文本,android,Android,我做了一个活动 在“订阅”按钮上,我必须向一些默认电子邮件发送电子邮件,我的代码为: 软件包sditm.app import android.R.string; import android.app.Activity; import android.content.ContentValues; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDa
import android.R.string;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class subscribeActivity extends Activity {
/** Called when the activity is first created. */
EditText name,age,address;
databaseforsubscribe addressBook;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subscribe);
Button store = (Button)findViewById(R.id.button1);
name=(EditText)findViewById(R.id.editText1);
age=(EditText)findViewById(R.id.editText2);
address=(EditText)findViewById(R.id.editText3);
addressBook = new databaseforsubscribe(this,"addressDB",null,2);
store.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String s=new String();
String m=new String();
String n=new String();
s=name.getText().toString();
m=age.getText().toString();
n=address.getText().toString();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, "aman4251@gmail.com");
// i.putExtra(Intent.EXTRA_EMAIL , new String[]{"aman4251@gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT ,"NAME: "+s+" ; MOBILE: "+m+" ; EMAIL: "+n);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(subscribeActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
});
}
}
这就打开了一个这样的意图
现在,我必须将电子邮件id设置为文本框并使其不可编辑,或者自动单击发送按钮,以便用户看不到此意图,并且电子邮件在后台发送。尝试以下代码:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.",Toast.LENGTH_SHORT).show();
}
嗨,试试这段代码
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Add attributes to the intent
sendIntent.putExtra(Intent.EXTRA_EMAIL, "");
sendIntent.putExtra(Intent.EXTRA_CC, "");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "");
sendIntent.putExtra(Intent.EXTRA_TEXT, "");
sendIntent.setType("text/plain");
PackageManager pm = getPackageManager();
List<ResolveInfo> activityList = pm
.queryIntentActivities(sendIntent, 0);
Iterator<ResolveInfo> it = activityList.iterator();
boolean isEmailSetUp = false;
while (it.hasNext()) {
ResolveInfo info = it.next();
if ("com.android.email.activity.MessageCompose"
.equalsIgnoreCase(info.activityInfo.name)) {
isEmailSetUp = true;
sendIntent.setClassName(info.activityInfo.packageName,
info.activityInfo.name);
}
}
if (isEmailSetUp) {
startActivity(sendIntent);
} else {
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setMessage("No Mail Accounts");
dlgAlert.setTitle("Please set up a Mail account in order to send email");
dlgAlert.setPositiveButton(getResources().getString(R.string.ok),
null);
dlgAlert.setCancelable(true);
dlgAlert.create().show();
}
我不知道是否有可能使电子邮件id编辑文本不可编辑 但你们可以通过点击按钮在后台发送邮件
这是我的密码,先生。我已经试过了。。请检查我的代码Aman,检查你的cade的这行:i.putExtraIntent.EXTRA_电子邮件,aman4251@gmail.com; 你在这里传递字符串。您需要像这样传递字符串数组:newstring[]{recipient@example.com}... 检查这个代码,是的,你已经在你的清单文件中添加了这个权限-我已经尝试过了,先生。。我已经说过了。。那也不管用。。我没有补充这一点。。如何认识他,阿曼。我试过这个密码。我没有改变任何事情。工作正常。电子邮件正在发送。它还显示在地址“收件人:”框中