* Furthermore this Activity contains a pick number button to starts dummy contacts activity to * demonstrate Intent stubbing. */ public class DialerActivity extends Activity { private static final int REQUEST_CODE_PICK = 16; private EditText mCallerNumber; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialer); mCallerNumber = (EditText) findViewById(R.id.edit_text_caller_number); } public void onCall(View view) { boolean hasCallPhonePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED; if (hasCallPhonePermission) startActivity(createCallIntentFromNumber()); else Toast.makeText(this, R.string.warning_call_phone_permission, Toast.LENGTH_SHORT).show(); } public void onPickContact(View view) { final Intent pickContactIntent = new Intent(this, ContactsActivity.class); startActivityForResult(pickContactIntent, REQUEST_CODE_PICK); } private Intent createCallIntentFromNumber() { final Intent intentToCall = new Intent(Intent.ACTION_CALL); String number = mCallerNumber.getText().toString(); intentToCall.setData(Uri.parse("tel:" + number)); return intentToCall; } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_PICK) { if (resultCode == RESULT_OK) { mCallerNumber.setText(data.getExtras() .getString(ContactsActivity.KEY_PHONE_NUMBER)); } } } }