Intent Implicit
Last updated
Was this helpful?
Last updated
Was this helpful?
Pada praktikum kali ini kita akan mencoba implementasi beberapa operasi di Intent Implicit seperti membuka Contact, Dialpad, Camera dan browser.
Untuk dapat mengakses ke activity 3, tambahkan
Untuk mengakses activity 3 ini, kita buat button baru di activity 2.
Tampilan activity 2 akan menjadi seperti ini
Jangan lupa tambahkan intent pada button di activity 2 untuk perpindahan ke activity 3.
Tambahkan komponen / widget button ke layout activity 3 .
<?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>
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;
}
}
}