khirulnizam

Complete call MainActivity

Dec 15th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. //package com.khirulnizam.myapplication;
  2.  
  3. import android.Manifest;
  4. import android.content.Intent;
  5. import android.content.pm.PackageManager;
  6. import android.net.Uri;
  7. import android.support.v4.app.ActivityCompat;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.Toast;
  14.  
  15. public class Call extends AppCompatActivity implements View.OnClickListener{
  16. //UI object
  17. EditText txtnama, txtphone;
  18. Button btncall;
  19.  
  20. @Override
  21. protected void onCreate(Bundle savedInstanceState) {
  22. super.onCreate(savedInstanceState);
  23. setContentView(R.layout.activity_call);
  24.  
  25. //UI binding
  26. txtnama=(EditText)findViewById(R.id.txtnama);
  27. txtphone=(EditText)findViewById(R.id.txtphone);
  28. btncall=(Button)findViewById(R.id.btncall);
  29. btncall.setOnClickListener(this);
  30. }
  31. public void onClick(View v){
  32. //capture nama & nombor phone
  33. String nama=txtnama.getText().toString();
  34. String phone=txtphone.getText().toString();
  35. String mesej = "Calling "+nama+" at "+phone;
  36. //display in
  37. Toast.makeText(this, mesej, Toast.LENGTH_LONG).show();
  38.  
  39. // pastebin.com/9SC19kWs
  40. Intent callIntent = new Intent(Intent.ACTION_CALL);
  41. callIntent.setData(Uri.parse("tel:"+txtphone.getText().toString()));
  42.  
  43. if (ActivityCompat.checkSelfPermission(Call.this,
  44. Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
  45. return;
  46. }
  47. startActivity(callIntent);
  48. }//end onClick
  49. }//end class
Advertisement
Add Comment
Please, Sign In to add comment