There is some useful Intent to open from our Application in android.
- Sending Email – There are many situations where we open email Intent for sending a message to a particular Email address.
1 2 3 4 5 6 7 8 9 |
void sendMail(String email){ Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( "mailto", email, null)); try { startActivity(Intent.createChooser(intent, "Send mail...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); } } |
- Dial Phone No. – There is a situation where we open Dial Intent for calling to a particular Telephone.
1 2 3 4 5 6 7 8 |
void call(String phoneNo){ Intent callIntent = new Intent(Intent.ACTION_DIAL); callIntent.setData(Uri.parse("tel:" + phoneNo)); // if (ActivityCompat.checkSelfPermission(ContactUs.this, android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { // return; // } ContactUs.this.startActivity(callIntent); } |
- Open WhatsApp application- There is a situation where we open WhatsApp application to sending a message to particular Mobile no.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
private void openWhatsapp(String info) { PackageManager pm = getPackageManager(); try { PackageInfo pInfo = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA); String smsNumber = info + "@s.whatsapp.net"; Uri uri = Uri.parse("smsto:" + smsNumber); Intent i = new Intent(Intent.ACTION_SENDTO, uri); i.setPackage("com.whatsapp"); startActivity(i); } catch (PackageManager.NameNotFoundException e){ showToast("Please install Whatsapp App"); } } |
where info is a WhatsApp mobile number.
- Open Device Browser- There are many situations where we required to open a URL into device Browser.
1 2 3 4 5 |
void openBrowser(String url){ Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } |
- For sending file via Gmail- Please check our blog