Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.message;
- import androidx.appcompat.app.AppCompatActivity;
- import android.Manifest;
- import android.app.PendingIntent;
- import android.content.Intent;
- import android.content.pm.PackageManager;
- import android.net.Uri;
- import android.os.Build;
- import android.os.Bundle;
- import android.telephony.SmsManager;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- public class MainActivity extends AppCompatActivity {
- EditText t1,t2;
- Button m;
- String ph,nm;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- t1=findViewById(R.id.textview1);
- t2=findViewById(R.id.textview2);
- m= findViewById(R.id.message);
- m.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if(Build.VERSION.SDK_INT >=Build.VERSION_CODES.M)
- {
- if(checkSelfPermission(Manifest.permission.CALL_PHONE)== PackageManager.PERMISSION_GRANTED)
- {
- Callphone();
- }
- else
- {
- requestPermissions(new String[]{Manifest.permission.CALL_PHONE},1);
- }
- }
- }
- });
- }
- public void Callphone()
- {
- ph=t1.getText().toString();
- Intent intent= new Intent(Intent.ACTION_CALL);
- intent.setData( Uri.parse("tel:"+ ph));
- startActivity(intent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment