Implicit Intent
Fri Apr 15 2022 05:21:40 GMT+0000 (Coordinated Universal Time)
Saved by @anasrathore #kotlin
<resources>
<string name="app_name">Implicit Intent Example</string>
<string name="phone_number">Phone Number</string>
<string name="call">Call</string>
<string name="call_logs">Call Logs</string>
<string name="contact">Contact</string>
<string name="web_browser">Web Browser</string>
<string name="gallery">Gallery</string>
<string name="camera">Camera</string>
<string name="alarm">Alarm</string>
</resources>
----
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:isScrollContainer="true">
<EditText
android:id="@+id/et_number"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="@string/phone_number"
android:inputType="number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn_call"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/call"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et_number" />
<Button
android:id="@+id/btn_call_log"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/call_logs"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_call" />
<Button
android:id="@+id/btn_contact"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/contact"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_call_log" />
<Button
android:id="@+id/btn_browser"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/web_browser"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_contact" />
<Button
android:id="@+id/btn_gallery"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/gallery"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_browser" />
<Button
android:id="@+id/btn_camera"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/camera"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_gallery" />
<Button
android:id="@+id/btn_alarm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/alarm"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_camera" />
</android.support.constraint.ConstraintLayout>
---
import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.provider.AlarmClock
import android.provider.CallLog
import android.provider.CallLog.*
import android.provider.ContactsContract
import android.provider.MediaStore
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import android.util.Log
import android.view.View
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
val CALL_REQUEST_CODE = 101
@SuppressLint("MissingPermission")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setupPermissions()
// Calling using intent
btn_call.setOnClickListener(View.OnClickListener {
val intent = Intent(Intent.ACTION_CALL)
intent.data = Uri.parse("tel:" + et_number.getText())
startActivity(intent)
})
// Call log
btn_call_log.setOnClickListener(View.OnClickListener {
val intent = Intent(Intent.ACTION_VIEW)
intent.type = Calls.CONTENT_TYPE
startActivity(intent)
})
//Contact
btn_contact.setOnClickListener(View.OnClickListener {
val intent = Intent(Intent.ACTION_PICK)
intent.type = ContactsContract.Contacts.CONTENT_TYPE
startActivity(intent)
})
// browser
btn_browser.setOnClickListener(View.OnClickListener {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("https://tutorial.eyehunts.com/")
startActivity(intent)
})
// Gallery
btn_gallery.setOnClickListener(View.OnClickListener {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("content://media/external/images/media/")
startActivity(intent)
})
// camera
btn_camera.setOnClickListener(View.OnClickListener {
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startActivity(intent)
})
// alarm
btn_alarm.setOnClickListener(View.OnClickListener {
val intent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
startActivity(intent)
})
}
private fun setupPermissions() {
val permission = ContextCompat.checkSelfPermission(this,
Manifest.permission.CALL_PHONE)
if (permission != PackageManager.PERMISSION_GRANTED) {
Log.i("noone", "Permission to Call has denied")
makeRequest()
}
}
private fun makeRequest() {
ActivityCompat.requestPermissions(this,
arrayOf(Manifest.permission.CALL_PHONE),
CALL_REQUEST_CODE)
}
}
----manfiest addition---
<uses-permission android:name="android.permission.CALL_PHONE" />
----
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.eyehunt.implicitintentexample">
<uses-permission android:name="android.permission.CALL_PHONE" />
<application <=Example
-------
val emailIntent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:abc@xyz.com")
}
startActivity(Intent.createChooser(emailIntent, "Send feedback"))
Email Intent



Comments