Sajib_Ahmed

CallApp

Mar 10th, 2021
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. package com.example.message;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.Manifest;
  6. import android.app.PendingIntent;
  7. import android.content.Intent;
  8. import android.content.pm.PackageManager;
  9. import android.net.Uri;
  10. import android.os.Build;
  11. import android.os.Bundle;
  12. import android.telephony.SmsManager;
  13. import android.view.View;
  14. import android.widget.Button;
  15. import android.widget.EditText;
  16.  
  17. public class MainActivity extends AppCompatActivity {
  18.     EditText t1,t2;
  19.     Button m;
  20.     String ph,nm;
  21.  
  22.     @Override
  23.     protected void onCreate(Bundle savedInstanceState) {
  24.         super.onCreate(savedInstanceState);
  25.         setContentView(R.layout.activity_main);
  26.         t1=findViewById(R.id.textview1);
  27.         t2=findViewById(R.id.textview2);
  28.         m= findViewById(R.id.message);
  29.         m.setOnClickListener(new View.OnClickListener() {
  30.             @Override
  31.             public void onClick(View view) {
  32.  
  33.                if(Build.VERSION.SDK_INT >=Build.VERSION_CODES.M)
  34.                {
  35.                    if(checkSelfPermission(Manifest.permission.CALL_PHONE)== PackageManager.PERMISSION_GRANTED)
  36.                    {
  37.                      Callphone();
  38.                    }
  39.                    else
  40.                    {
  41.                        requestPermissions(new String[]{Manifest.permission.CALL_PHONE},1);
  42.                    }
  43.                }
  44.  
  45.             }
  46.         });
  47.  
  48.  
  49.     }
  50.     public void Callphone()
  51.     {
  52.         ph=t1.getText().toString();
  53.         Intent intent= new Intent(Intent.ACTION_CALL);
  54.         intent.setData( Uri.parse("tel:"+ ph));
  55.         startActivity(intent);
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment