Android Email Intent , Call Intent , Open URL Intent , WhatsApp Intent , YouTube Intent

1.4kviews
Android Email Intenti, Call Intent, Open URL Intent, WhatsApp Intent , YouTube Intent
Hiii In this Artical I am sharing how to open an email on button click, and also Call a number to a button click, and open URL in Web Browser, and open WhatsApp on button click in your App.
It’s a very easy way to used simple call intent, URL Open, Email Intent, WhatsApp used in your project according to your requirement.
Email Intent:- Open Email on button click on your project ;
Email.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String Email=CompanyEmail.getText().toString().trim();
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + Email));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
emailIntent.putExtra(Intent.EXTRA_TEXT, "");
//emailIntent.putExtra(Intent.EXTRA_HTML_TEXT, body); //If you are using HTML in your body text
startActivity(Intent.createChooser(emailIntent, "Chooser Title"));
}
});
Call Intent:- Call a number to click on the button and call a number
Call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String Phone = CompanyEmail.getText().toString().trim();
Intent i = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Phone));
if (ActivityCompat.checkSelfPermission(Contact_Us.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
startActivity(i);
}
});
URL Open:- URL Open Intent to open URL in browser click on the button ;
WebSite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = CompanyWeb.getText().toString().trim();
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
}
});
WhatsApp Intent:- Open WhatsApp on button click and send a message ;
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Hiii i am hare help me");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(sendIntent);
}else {
Toast.makeText(Home.this,"whatsapp not install please install whatsapp",Toast.LENGTH_LONG).show();
}
break;
YouTube Intent:- Open a YouTube Channel, Video on your App Button click open in your YouTube.
YoutubeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/channel/UCS32LVFANht2yRI5w8X_1CQ")));
}
});




