-1

I want to call that number when I click on it, and an email should be send to that email on click on the email address I have given in my application,

here is my code,

tvcontactphone.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }
    });

    tvcontactemail.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });

Now What should I write in this two method to perform the action?

this my image of application,

enter image description here

when I click on red link it should move to the email and when I click on the phone number in white colour that number should be call or it should move to the phone call application, same should be done in email.

Kara
  • 6,115
  • 16
  • 50
  • 57
akky777
  • 423
  • 2
  • 6
  • 23

4 Answers4

2
  String phoneCallUri = "tel:"+ tvcontactphone.getText().toString();
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
phoneCallIntent.setData(Uri.parse(phoneCallUri));
startActivity(phoneCallIntent);
Karthick pop
  • 616
  • 3
  • 16
2

For both you should use intents, like here:

For mail, look here: Send Email Intent

one of the answers is this, that works for my needs:

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
        "mailto","abc@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "EXTRA_SUBJECT");
startActivity(Intent.createChooser(emailIntent, "Send email..."));

For calls, look here: Call intent in Android

one of the answers is this, that works for my needs:

Intent dial = new Intent();
dial.setAction("android.intent.action.DIAL");
dial.setData(Uri.parse("tel:"));
startActivity(dial);

.. you shouldn't start a call directly from the app, its better to make an intent, which calls the dialer, and takes the phone number with it ;-)

Community
  • 1
  • 1
Niklas Zantner
  • 182
  • 2
  • 16
1
 Intent callIntent = new Intent(Intent.ACTION_CALL);          
            callIntent.setData(Uri.parse("tel:"+phone));          
            startActivity(callIntent);
Digvesh Patel
  • 6,503
  • 1
  • 20
  • 34
0

Implement this for call

tvcontactphone.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
    Intent callIntent = new Intent(Intent.ACTION_CALL);  
    callIntent.setData(Uri.parse("tel:"+tvcontactphone.getText().toString()));  
    startActivity(callIntent);
    }
});

and for Email

tvcontactemail.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain"); 
        intent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { tvcontactemail.getText().toString() });
        intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT");
        intent.putExtra(android.content.Intent.EXTRA_TEXT,YOURTEXT);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(android.content.Intent.createChooser(intent, "Choose an Email client :"));
    }
});
SMR
  • 6,628
  • 2
  • 35
  • 56