我正在使用Google Vision OCR从名片中提取电子邮件(OCR图形活动),并将其发送到SendEmail活动中的“收件人”目的地。我的日志显示检测到电子邮件文本。
我试图设置将其发送到下一个活动的意图,但是我遇到两个错误,新意图“无法解析构造函数意图”,并且开始活动无法应用。
这是OcrGraphic活动
List<Line> lines = (List<Line>) text.getComponents();
for(Line elements : lines) {
float left = translateX(elements.getBoundingBox().left);
float bottom = translateY(elements.getBoundingBox().bottom);
if (elements != null && elements.getValue() != null) {
if (elements.getValue().matches("^[_A-Za-z0-9-\\\\+]+(\\\\.[_A-Za-z0-9-]+)*@\"\n" +
"\t\t+ \"[A-Za-z0-9-]+(\\\\.[A-Za-z0-9]+)*(\\\\.[A-Za-z]{2,})$") || elements.getValue().contains("@")) {
Log.e("elementsemail", elements.getValue());
String email;
email = elements.getValue();
cEmail = email;
Intent sendIntent = new Intent(this, SendEmail.class);
sendIntent.putExtra(Intent.EXTRA_EMAIL, cEmail);
startActivity(sendIntent);
}
这是我的“发送电子邮件”活动
private void sendMail(){
Intent getIntent = getIntent();
String recipientList = getIntent.getStringExtra(OcrGraphic.cEmail);;
String[] recipients = recipientList.split(",");
String subject = mEditTextSubject.getText().toString();
String message = mEditTextMessage.getText().toString();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "Choose an email client"));
}
我想将电子邮件地址发送到SendEmail活动。我是java和android的新手,欢迎任何帮助。
答案 0 :(得分:0)
我认为您的问题是如何获得额外的(EXTRA_EMAIL)
将String recipientList = getIntent.getStringExtra(OcrGraphic.cEmail);;
替换为String recipientList = getIntent.getStringExtra(Intent.EXTRA_EMAIL);
答案 1 :(得分:0)
请替换为:
Intent sendIntent = new Intent(this, SendEmail.class);
这是什么:
Intent sendIntent = new Intent(getApplicationContext(), SendEmail.class);
修改
您需要在这样的构造函数中传递上下文
private Context context;
OcrGraphic(GraphicOverlay overlay, TextBlock text, Context context) {
super(overlay);
this.context = context;
}
然后
Intent sendIntent = new Intent(context, SendEmail.class);