International Islamic University H-10, Islamabad, Pakistan
Mobile Applications Development
Week 07
Using Implicit Intents
in Android
Engr. Rashid Farid Chishti
http://youtube.com/rfchishti
http://sites.google.com/site/chisht
i
 An Implicit Intent in Android is used when you want the system (or another
app) to handle an action, without specifying which exact app or component
should do it.
 Instead of saying “Open SecondActivity in my app” (explicit intent), you say “I
want to share this text” or “I want to open this webpage”, and Android finds
the best app available to handle it.
 Example:
 Open a webpage in browser
 Share data (text/document/image/video etc.)
 Send an email
 Make a phone call
 Pick an image from gallery
What are Implicit Intents?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/btn_share_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Share a Text" />
1. Implicit Intent (activity_main.xml) (1/3)
<Button
android:id="@+id/btn_open_web"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Open a Webpage" />
<Button
android:id="@+id/btn_make_call"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Make Phone Call" />
<Button
android:id="@+id/btn_send_sms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Send an SMS" />
1. Implicit Intent (activity_main.xml) (2/3)
<Button
android:id="@+id/btn_send_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Send an Email" />
<Button
android:id="@+id/btn_set_alarm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Set an Alarm" />
</LinearLayout>
1. Implicit Intent (activity_main.xml) (3/3)
package com.example.myfirstapp
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.AlarmClock
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -
>
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
1. Implicit Intent (MainActivity.kt) (1/5)
v.setPadding(systemBars.left, systemBars.top, systemBars.right,
systemBars.bottom)
insets
}
val btn_share_text = findViewById<Button>(R.id.btn_share_text)
val btn_open_web = findViewById<Button>(R.id.btn_open_web)
val btn_make_call = findViewById<Button>(R.id.btn_make_call)
val btn_send_sms = findViewById<Button>(R.id.btn_send_sms)
val btn_send_email = findViewById<Button>(R.id.btn_send_email)
val btn_set_alarm = findViewById<Button>(R.id.btn_set_alarm)
btn_share_text.setOnClickListener {
val intent = Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, "Hello from My App")
}
// Opens share sheet for apps like WhatsApp, Messages, etc.
👉
startActivity(Intent.createChooser(intent, "Share via"))
}
1. Implicit Intent (MainActivity.kt) (2/5)
btn_open_web.setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("https://chishti.web.app")
startActivity(intent)
}
btn_make_call.setOnClickListener {
val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:03340644440")
startActivity(intent)
}
btn_send_sms.setOnClickListener {
val intent = Intent(Intent.ACTION_SENDTO,
Uri.parse("smsto:03340644440"))
intent.putExtra("sms_body", "Hi!")
startActivity(intent)
}
1. Implicit Intent (MainActivity.kt) (3/5)
btn_send_email.setOnClickListener {
// Create intent
val intent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:") // only email apps should handle this
putExtra(Intent.EXTRA_EMAIL, arrayOf("chishti@iiu.edu.pk"))
putExtra(Intent.EXTRA_SUBJECT, "Subject here")
putExtra(Intent.EXTRA_TEXT, "Hello, this is the email body.")
}
// Verify there is an email app
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
}
// Lets the user choose an email app.
startActivity(Intent.createChooser(intent, "Send Email via:"))
}
1. Implicit Intent (MainActivity.kt) (4/5)
btn_set_alarm.setOnClickListener {
val intent = Intent(AlarmClock.ACTION_SET_ALARM).apply {
putExtra(AlarmClock.EXTRA_HOUR, 7);
putExtra(AlarmClock.EXTRA_MINUTES, 30)
}
startActivity(intent)
}
}
}
1. Implicit Intent (MainActivity.kt) (5/5)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyFirstApp">
<activity android:name=".Activity_Second" android:exported="false" />
<activity android:name=".MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </activity> </application> </manifest>
1. Implicit Intent (AndroidManifest.xml)
 You don’t specify the exact activity/component → Android decides which app
can handle it.
 Use standard Intent actions (e.g., ACTION_VIEW, ACTION_SEND, ACTION_DIAL).
 Always use Intent.createChooser() for better UX.
 Always check with resolveActivity() to prevent crashes if no app is available.
 Good for inter-app communication (e.g., send an email, share an image, open
a map).
 In Short:
 Explicit Intent → “Go to this activity in my app.”
 Implicit Intent → “I want to do this action, any app that can help?”
Key Points About Implicit Intents

Week 07 - Using Implicit Intents in Android.pptx

  • 1.
    International Islamic UniversityH-10, Islamabad, Pakistan Mobile Applications Development Week 07 Using Implicit Intents in Android Engr. Rashid Farid Chishti http://youtube.com/rfchishti http://sites.google.com/site/chisht i
  • 2.
     An ImplicitIntent in Android is used when you want the system (or another app) to handle an action, without specifying which exact app or component should do it.  Instead of saying “Open SecondActivity in my app” (explicit intent), you say “I want to share this text” or “I want to open this webpage”, and Android finds the best app available to handle it.  Example:  Open a webpage in browser  Share data (text/document/image/video etc.)  Send an email  Make a phone call  Pick an image from gallery What are Implicit Intents?
  • 3.
  • 4.
    <Button android:id="@+id/btn_open_web" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="Open a Webpage"/> <Button android:id="@+id/btn_make_call" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="Make Phone Call" /> <Button android:id="@+id/btn_send_sms" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="Send an SMS" /> 1. Implicit Intent (activity_main.xml) (2/3)
  • 5.
    <Button android:id="@+id/btn_send_email" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="Send an Email"/> <Button android:id="@+id/btn_set_alarm" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="Set an Alarm" /> </LinearLayout> 1. Implicit Intent (activity_main.xml) (3/3)
  • 6.
    package com.example.myfirstapp import android.content.Intent importandroid.net.Uri import android.os.Bundle import android.provider.AlarmClock import android.widget.Button import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContentView(R.layout.activity_main) ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets - > val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) 1. Implicit Intent (MainActivity.kt) (1/5)
  • 7.
    v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) insets } valbtn_share_text = findViewById<Button>(R.id.btn_share_text) val btn_open_web = findViewById<Button>(R.id.btn_open_web) val btn_make_call = findViewById<Button>(R.id.btn_make_call) val btn_send_sms = findViewById<Button>(R.id.btn_send_sms) val btn_send_email = findViewById<Button>(R.id.btn_send_email) val btn_set_alarm = findViewById<Button>(R.id.btn_set_alarm) btn_share_text.setOnClickListener { val intent = Intent(Intent.ACTION_SEND).apply { type = "text/plain" putExtra(Intent.EXTRA_TEXT, "Hello from My App") } // Opens share sheet for apps like WhatsApp, Messages, etc. 👉 startActivity(Intent.createChooser(intent, "Share via")) } 1. Implicit Intent (MainActivity.kt) (2/5)
  • 8.
    btn_open_web.setOnClickListener { val intent= Intent(Intent.ACTION_VIEW) intent.data = Uri.parse("https://chishti.web.app") startActivity(intent) } btn_make_call.setOnClickListener { val intent = Intent(Intent.ACTION_DIAL) intent.data = Uri.parse("tel:03340644440") startActivity(intent) } btn_send_sms.setOnClickListener { val intent = Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:03340644440")) intent.putExtra("sms_body", "Hi!") startActivity(intent) } 1. Implicit Intent (MainActivity.kt) (3/5)
  • 9.
    btn_send_email.setOnClickListener { // Createintent val intent = Intent(Intent.ACTION_SENDTO).apply { data = Uri.parse("mailto:") // only email apps should handle this putExtra(Intent.EXTRA_EMAIL, arrayOf("chishti@iiu.edu.pk")) putExtra(Intent.EXTRA_SUBJECT, "Subject here") putExtra(Intent.EXTRA_TEXT, "Hello, this is the email body.") } // Verify there is an email app if (intent.resolveActivity(packageManager) != null) { startActivity(intent) } // Lets the user choose an email app. startActivity(Intent.createChooser(intent, "Send Email via:")) } 1. Implicit Intent (MainActivity.kt) (4/5)
  • 10.
    btn_set_alarm.setOnClickListener { val intent= Intent(AlarmClock.ACTION_SET_ALARM).apply { putExtra(AlarmClock.EXTRA_HOUR, 7); putExtra(AlarmClock.EXTRA_MINUTES, 30) } startActivity(intent) } } } 1. Implicit Intent (MainActivity.kt) (5/5)
  • 11.
    <?xml version="1.0" encoding="utf-8"?> <manifestxmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="com.android.alarm.permission.SET_ALARM" /> <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyFirstApp"> <activity android:name=".Activity_Second" android:exported="false" /> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 1. Implicit Intent (AndroidManifest.xml)
  • 12.
     You don’tspecify the exact activity/component → Android decides which app can handle it.  Use standard Intent actions (e.g., ACTION_VIEW, ACTION_SEND, ACTION_DIAL).  Always use Intent.createChooser() for better UX.  Always check with resolveActivity() to prevent crashes if no app is available.  Good for inter-app communication (e.g., send an email, share an image, open a map).  In Short:  Explicit Intent → “Go to this activity in my app.”  Implicit Intent → “I want to do this action, any app that can help?” Key Points About Implicit Intents