Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package com.khirulnizam.myapplication;
- import android.Manifest;
- import android.content.Intent;
- import android.content.pm.PackageManager;
- import android.net.Uri;
- import android.support.v4.app.ActivityCompat;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class Call extends AppCompatActivity implements View.OnClickListener{
- //UI object
- EditText txtnama, txtphone;
- Button btncall;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_call);
- //UI binding
- txtnama=(EditText)findViewById(R.id.txtnama);
- txtphone=(EditText)findViewById(R.id.txtphone);
- btncall=(Button)findViewById(R.id.btncall);
- btncall.setOnClickListener(this);
- }
- public void onClick(View v){
- //capture nama & nombor phone
- String nama=txtnama.getText().toString();
- String phone=txtphone.getText().toString();
- String mesej = "Calling "+nama+" at "+phone;
- //display in
- Toast.makeText(this, mesej, Toast.LENGTH_LONG).show();
- // pastebin.com/9SC19kWs
- Intent callIntent = new Intent(Intent.ACTION_CALL);
- callIntent.setData(Uri.parse("tel:"+txtphone.getText().toString()));
- if (ActivityCompat.checkSelfPermission(Call.this,
- Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
- return;
- }
- startActivity(callIntent);
- }//end onClick
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment