Skip to content

Instantly share code, notes, and snippets.

@shubhamnikam
Created September 3, 2018 12:34
Show Gist options
  • Save shubhamnikam/a725da8fd7a84885313fd72579436e2e to your computer and use it in GitHub Desktop.
Save shubhamnikam/a725da8fd7a84885313fd72579436e2e to your computer and use it in GitHub Desktop.
Implicit Intent - Phone Call
intentPhoneCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_CALL);
String phoneNumber = "1234567890";
intent.setData(Uri.parse("tel:" + phoneNumber));
if (intent.resolveActivity(getPackageManager()) != null) {
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.READ_CONTACTS)) {
} else {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.CALL_PHONE}, 1);
Toast.makeText(MainActivity.this, "You need to accept the permission to make a phone call.", Toast.LENGTH_SHORT).show();
}
} else {
startActivity(intent);
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment