Created
September 3, 2018 12:34
-
-
Save shubhamnikam/a725da8fd7a84885313fd72579436e2e to your computer and use it in GitHub Desktop.
Implicit Intent - Phone Call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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