Tutorial 6

Use device actions safely.

A catalogue becomes useful when users can call, open maps, or share. Prefer external intents when another app already owns the job.

Action map

CallOpen dialer with a phone number. Avoid direct call permission unless required.
MapOpen location in a maps app using a geo or search URI.
ShareUse system share sheet for business name, phone, and address.

Open dialer

fun openDialer(context: Context, phone: String) {
    val intent = Intent(
        Intent.ACTION_DIAL,
        Uri.parse("tel:$phone")
    )
    context.startActivity(intent)
}

ACTION_DIAL opens the dialer and lets the user decide. That is safer than making the call directly.

Practice task

  • Add Call, Map, and Share buttons to the detail screen.
  • Disable Call when phone is missing.
  • Test the action on emulator and real device if possible.
  • Document which actions need permissions and which do not.