Useful intents functionality to send mail, Call to the number and Show Direction on Map.

Hitesh Dhamshaniya
1 min readAug 23, 2019

--

As application developer (android) you frequently need to implement common functionality like call, mail or show direction on the map.

//For open dial pad from android application
fun
launchCall(mActivity: Activity, phoneNumber: String) {
val intent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:$phoneNumber"))
mActivity.startActivity(intent)
}

I used ACTION_DIAL instead of ACTION_CALl becuase action_call require permission define in menifest.xml and action_dial don’t require any. So later better to user.

fun launchMail(mActivity: Activity, emailAddress: String) {
val intent = Intent(Intent.ACTION_SENDTO)
intent.type = "text/html"
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@gmail.com")
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject")
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.")
mActivity.startActivity(Intent.createChooser(intent, "Send Email"))
}

Above code used to open Email client from application, used ACTION_SENDTO because its only show email client not other application i.e twitter, facebook etc.. so its better to user ACTION_SENDTO instead of ACTION_SEND.

fun launchMap(mActivity: Activity, lat: String, lng: String) {
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=$lat,$lng (Mas Insurance Group)")
)
mActivity.startActivity(intent)
}

To launch map with specif location call Intent.ACTION_VIEW and set Geo location.

One can simply create IntentHelper class and put all related method there, which will easy to use.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Hitesh Dhamshaniya
Hitesh Dhamshaniya

No responses yet

Write a response