package cc.i420.intent; import android.content.Intent; import android.net.Uri; import android.provider.ContactsContract; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private Intent i; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnURL = findViewById(R.id.btnURL); btnURL.setOnClickListener(this); Button btnEmail = findViewById(R.id.btnEmail); btnEmail.setOnClickListener(this); Button btnCall = findViewById(R.id.btnCall); btnCall.setOnClickListener(this); Button btnCamera = findViewById(R.id.btnCamera); btnCamera.setOnClickListener(this); Button btnMap = findViewById(R.id.btnMap); btnMap.setOnClickListener(this); Button btnGallery = findViewById(R.id.btnGallery); btnGallery.setOnClickListener(this); Button btnContact = findViewById(R.id.btnContact); btnContact.setOnClickListener(this); Button btnPlay = findViewById(R.id.btnPlay); btnPlay.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btnURL: i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/")); startActivity(i); //finish(); break; case R.id.btnEmail: i = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:")); startActivity(i); //finish(); break; case R.id.btnCall: i = new Intent(Intent.ACTION_DIAL); startActivity(i); //finish(); break; case R.id.btnCamera: i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivity(i); //finish(); break; case R.id.btnMap: i = new Intent(Intent.ACTION_VIEW); i.setPackage("com.google.android.apps.maps"); startActivity(i); //finish(); break; case R.id.btnGallery: i = new Intent(Intent.ACTION_PICK); i.setType("image/*"); startActivity(i); //finish(); break; case R.id.btnContact: i = new Intent(Intent.ACTION_PICK); i.setType(ContactsContract.Contacts.CONTENT_TYPE); startActivity(i); //finish(); break; case R.id.btnPlay: i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/")); startActivity(i); //finish(); break; } } }
Monday, June 18, 2018
Android intentButtons
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment