Phone Call in Android

I used following code for phone call.But the call is not working .can anyone help me? I also given manfest Call Phone permission.

 call = (TextView) findViewById(R.id.GuestPhoneNo1);
        call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String no = call.getText().toString();
            //    Toast.makeText(Accepted_Details.this, no, Toast.LENGTH_SHORT).show();
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:" + no));


                /*if (ActivityCompat.checkSelfPermission(Accepted_Details.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    // TODO: Consider calling
                    //    ActivityCompat#requestPermissions
                    // here to request the missing permissions, and then overriding
                    //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                    //                                          int[] grantResults)
                    // to handle the case where the user grants the permission. See the documentation
                    // for ActivityCompat#requestPermissions for more details.
                    return;
                }*/
                startActivity(callIntent);
            }
        });
spectrumsofttechAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
public class MainActivity extends AppCompatActivity {

private static final int MAKE_CALL_PERMISSION_REQUEST_CODE = 1;
private Button dial;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    dial = (Button) findViewById(R.id.dial);
    final EditText numberToDial = (EditText) findViewById(R.id.number);

    dial.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String phoneNumber = numberToDial.getText().toString();

            if (!TextUtils.isEmpty(phoneNumber)) {
                if (checkPermission(Manifest.permission.CALL_PHONE)) {
                    String dial = "tel:" + phoneNumber;
                    startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
                } else {
                    Toast.makeText(MainActivity.this, "Permission Call Phone denied", Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(MainActivity.this, "Enter a phone number", Toast.LENGTH_SHORT).show();
            }
         }
    });

    if (checkPermission(Manifest.permission.CALL_PHONE)) {
        dial.setEnabled(true);
    } else {
        dial.setEnabled(false);
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, MAKE_CALL_PERMISSION_REQUEST_CODE);
    }
}

private boolean checkPermission(String permission) {
    return ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED;
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    switch(requestCode) {
        case MAKE_CALL_PERMISSION_REQUEST_CODE :
            if (grantResults.length > 0 && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
                dial.setEnabled(true);
                Toast.makeText(this, "You can call the number by clicking on the button", Toast.LENGTH_SHORT).show();
            }
            return;
    }
}
}

Open in new window

source: https://stackoverflow.com/questions/50386017/phone-call-in-android
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Smartphone Programming

From novice to tech pro — start learning today.