How do I fix "startActivity() in ContextCompat cannot be applied to?"

I am using Google Vision OCR to grab the email from a business card (the OCR Graphic activity) and send it to the the To destination in the SendEmail activity. My log shows that the email text is detected.

I tried to set the intent to send it to the next activity, but I am getting two errors, "cannot resolve constructor Intent" on my new intent, and start activity cannot be applied to.

This is the OcrGraphic activity

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);


this is my Send Email activity

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);
        startActivity(Intent.createChooser(intent, "Choose an email client"));

I want to send the email address to the SendEmail activity. I am new to java and android, any help is welcomed.

- - Source


answered 1 week ago Aaron Ayalew #1

I think you're problem is how you obtain the extra(EXTRA_EMAIL)
Replace String recipientList = getIntent.getStringExtra(OcrGraphic.cEmail);; with String recipientList = getIntent.getStringExtra(Intent.EXTRA_EMAIL);

answered 1 week ago ismail alaoui #2

please replace this :

Intent sendIntent = new Intent(this, SendEmail.class);

whit this :

Intent sendIntent = new Intent(getApplicationContext(), SendEmail.class);


You need to pass context in a constructor like this

private Context context;

OcrGraphic(GraphicOverlay overlay, TextBlock text, Context context) { 
       this.context = context; 

And then

Intent sendIntent = new Intent(context, SendEmail.class);

comments powered by Disqus