activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation='vertical'>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to implicit exampele"
/>
<Button
android:id="@+id/opencam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Open Camera" />
</LinearLayout>
MainActivity.kt
package com.androidina.implicit
import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.provider.MediaStore
import android.widget.Button
class MainActivity : AppCompatActivity() {
var btncam: Button?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btncam=findViewById(R.id.opencam)
btncam!!.setOnClickListener {
var cam=Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startActivity(cam)
}
}
}