# Intent Implicit

Pada praktikum kali ini kita akan mencoba implementasi beberapa operasi di Intent Implicit seperti membuka Contact, Dialpad, Camera dan browser.

![](https://3649984872-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Liug3JlzqTO7wMX8AdN%2F-Lj-GuIDTvvflX0sOcTo%2F-Lj-GvHR0TI7L2jiiLpZ%2Fimage.png?alt=media\&token=7ffb9912-9d9a-4e94-935f-2977eeeeac62)

#### Buat Activity baru

Untuk dapat mengakses ke activity 3, tambahkan

![ThirdActivity](https://3649984872-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Liug3JlzqTO7wMX8AdN%2F-Lj-GuIDTvvflX0sOcTo%2F-Lj-HGGnRnNvmnIVuSJs%2Fimage.png?alt=media\&token=9587693b-93e3-49d9-a2d8-bf0ebddfbb17)

#### Button Activity 3&#x20;

* Untuk mengakses activity 3 ini, kita buat button baru di activity 2.

![activity\_second.xml](https://3649984872-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Liug3JlzqTO7wMX8AdN%2F-Lj-GuIDTvvflX0sOcTo%2F-Lj-H_mLK2WIy3SHWbPg%2Fimage.png?alt=media\&token=f22fcb97-2e6d-4240-b421-dfbcbd03f631)

* Tampilan activity 2 akan menjadi seperti ini

![](https://3649984872-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Liug3JlzqTO7wMX8AdN%2F-Lj-GuIDTvvflX0sOcTo%2F-Lj-Hl-uZJKjXxcs2Zka%2Fimage.png?alt=media\&token=a509d5e7-1330-47bf-b5dd-a80ec7d8d4d7)

* Jangan lupa tambahkan intent pada button di activity 2 untuk perpindahan ke activity 3.

![](https://3649984872-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Liug3JlzqTO7wMX8AdN%2F-Lj-GuIDTvvflX0sOcTo%2F-Lj-IaUkznZ6PmuflU4R%2Fimage.png?alt=media\&token=766b1a50-734d-4688-a4f2-c17abdbe10cb)

#### Desain Layout Activity 3

* Tambahkan komponen / widget button ke layout activity 3 .

{% code title="activity\_third.xml" %}

```
<?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:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="16dp"
    tools:context=".ThirdActivity">

    <EditText
        android:id="@+id/etNo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter phone no."
        android:inputType="phone"
        android:textColor="@android:color/holo_red_light" />


    <Button
        android:id="@+id/btnCamera"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Camera"
        android:textColor="@android:color/holo_red_light" />

    <Button
        android:id="@+id/btnContact"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Contact"
        android:textColor="@android:color/holo_red_light" />

    <Button
        android:id="@+id/btnBrowser"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Browser"
        android:textColor="@android:color/holo_red_light" />

    <Button
        android:id="@+id/btnGallery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Gallery"
        android:textColor="@android:color/holo_red_light" />

    <Button
        android:id="@+id/btnDial"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Dialpad"
        android:textColor="@android:color/holo_red_light" />

</LinearLayout>

```

{% endcode %}

#### Logic di Activity 3

```
public class ThirdActivity extends AppCompatActivity implements View.OnClickListener {

    Button btnCamera, btnContact, btnBrowser, btnGallery, btnDial;

    EditText etNo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third);

        etNo = findViewById(R.id.etNo);

        btnCamera = findViewById(R.id.btnCamera);
        btnBrowser = findViewById(R.id.btnBrowser);
        btnGallery = findViewById(R.id.btnGallery);
        btnDial = findViewById(R.id.btnDial);
        btnContact = findViewById(R.id.btnContact);


        btnDial.setOnClickListener(this);
        btnCamera.setOnClickListener(this);
        btnBrowser.setOnClickListener(this);
        btnContact.setOnClickListener(this);
        btnGallery.setOnClickListener(this);


    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.btnDial:
                Intent i = new Intent();
                i.setAction(Intent.ACTION_DIAL);
                i.setData(Uri.parse("tel:" + etNo.getText()));
                startActivity(i);
                break;

            case R.id.btnCamera:
                Intent iCamera = new Intent();
                iCamera.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
                startActivity(iCamera);
                break;

            case R.id.btnGallery:
                Intent iGallery = new Intent();
                iGallery.setAction(Intent.ACTION_VIEW);
                iGallery.setData(Uri.parse("content://media/external/images/media/"));
                startActivity(iGallery);
                break;

            case R.id.btnBrowser:
                Intent iBrowser = new Intent();
                iBrowser.setAction(Intent.ACTION_VIEW);
                iBrowser.setData(Uri.parse("http://www.google.com/"));
                startActivity(Intent.createChooser(iBrowser, "Title"));
                break;

            case R.id.btnContact:
                Intent iContact = new Intent();
                iContact.setAction(Intent.ACTION_VIEW);
                iContact.setData(Uri.parse("content://contacts/people/"));
                startActivity(iContact);
                break;

            default:
                break;
        }
    }
}
```

#### Jalankan Aplikasi anda

![](https://3649984872-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Liug3JlzqTO7wMX8AdN%2F-Lj-GuIDTvvflX0sOcTo%2F-Lj-IkXSLcZoPKQFVpsJ%2Fimage.png?alt=media\&token=63692ab8-a24e-4a11-886b-951a4918c120)
