Advertisement
Baru_Berbagi

MainActivity.java

Oct 26th, 2021
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. package com.baruberbagi.callphone;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.content.Intent;
  6. import android.net.Uri;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12.  
  13. public class MainActivity extends AppCompatActivity {
  14.  
  15.     Button permanencall,manualCall;
  16.     EditText edtManual;
  17.     String noTLP = "tel:1234567";
  18.  
  19.     @Override
  20.     protected void onCreate(Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         setContentView(R.layout.activity_main);
  23.  
  24.         permanencall = findViewById(R.id.btnPermanenCall);
  25.         manualCall = findViewById(R.id.btnManualCall);
  26.         edtManual = findViewById(R.id.edtManual);
  27.  
  28.         permanencall.setOnClickListener(new View.OnClickListener() {
  29.             @Override
  30.             public void onClick(View v) {
  31.                 Intent intent = new Intent(Intent.ACTION_DIAL);
  32.                 intent.setData(Uri.parse(noTLP));
  33.                 startActivity(intent);
  34.             }
  35.         });
  36.  
  37.  
  38.         manualCall.setOnClickListener(new View.OnClickListener() {
  39.             @Override
  40.             public void onClick(View v) {
  41.                 String nomor = edtManual.getText().toString();
  42.                if (nomor.equals("")){
  43.                    edtManual.setError("Harus di isi");
  44.                }else {
  45.                    Intent i = new Intent(Intent.ACTION_DIAL);
  46.                    i.setData(Uri.parse("tel:"+nomor));
  47.                    startActivity(i);
  48.                }
  49.             }
  50.         });
  51.  
  52.  
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement