Java intent class for url and phone and others

ww‮al.w‬utturi.com
Java intent class for url and phone and others

In Android, the Intent class is used to perform various actions, such as launching an activity, starting a service, delivering a broadcast, and more. You can use an Intent to launch a web browser to a specific URL, dial a phone number, or send an email, among other things.

Here are some examples of how to use the Intent class to perform these actions:

  • To launch a web browser to a specific URL:
String url = "https://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
  • To dial a phone number:
String phoneNumber = "1234567890";
Intent i = new Intent(Intent.ACTION_DIAL);
i.setData(Uri.parse("tel:" + phoneNumber));
startActivity(i);
  • To send an email:
String email = "example@example.com";
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("mailto:" + email));
i.putExtra(Intent.EXTRA_SUBJECT, "subject");
i.putExtra(Intent.EXTRA_TEXT, "body");
startActivity(i);

For more information on the Intent class in Android, you can refer to the Android documentation.

Created Time:2017-11-03 23:27:13  Author:lautturi