public class PhoneMainActivity extends AppCompatActivity { private Button button; private EditText editText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_phone_main); setView(); } private void setView() { button = (Button) findViewById(R.id.button); editText = (EditText) findViewById(R.id.editText); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (editText.getText().toString() == null) return; String phone = editText.getText().toString(); Intent intent = new Intent(Intent.ACTION_CALL); Uri data = Uri.parse("tel:" + phone); intent.setData(data); if (ActivityCompat.checkSelfPermission(PhoneMainActivity.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(intent); } }); }
1111111
Intent intent = new Intent(Intent.ACTION_CALL);//ZHIJIEIntent intent = new Intent(Intent.ACTION_DIAL);//JIANJIE