No matter how much you find out how to make a call without confirmation on the net
Intent intent = new Intent(Intent.ACTION_DIAL, "tel:0123345678); ACTION_DIAL Intent intent = new Intent(Intent.ACTION_CALL, "tel:012345678"); It says OK just by setting ACTION_CALL like, but when I execute it, it falls for some reason (? _?)
Of course, in AbdroidManifest.xml, uses-permission android:name="android.permission.CALL_PHONE" I didn't forget to put it in, and when I was wondering why, It turns out that we have to give the app access to CALL_PHONE.
When I started the app, I had to display the permission dialog that gives access rights as shown below. CALL_PHONE is dangerous permission, so you have to get permission from each user (^^;)
public class MainActivity extends AppCompatActivity { static final int REQUEST_CODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE)==PackageManager.PERMISSION_DENIED) {
ActivityCompat.requestPermissions(
this, new String[] { Manifest.permission.CALL_PHONE }, REQUEST_CODE);
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (requestCode == REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Dangerous permission request allowed } else { Toast toast = Toast.makeText (getApplicationContext (), "Cannot be used without adding phone function permissions", Toast.LENGTH_LONG); toast.show(); finish(); } } }
Recommended Posts