I have an EditView where the user is supposed to input a phone number. I then want to take that phone number and call/text it in another activity. How could I do that?
This is part of my Main Activity:
EditText editText = (EditText) findViewById(R.id.editText1);
editText.setOnClickListener(this);
}
public void onClick(View src) {
Intent serviceIntent = new Intent(this, MyService.class);
switch (src.getId()) {
case R.id.button1:
Log.d(TAG, "onClick: starting service");
EditText editText = (EditText) findViewById(R.id.editText1);
if (editText.getText().toString()==""){
Toast.makeText(getApplicationContext(), "Please enter a phone number", Toast.LENGTH_SHORT).show();
} else {
pnumber = editText.getText().toString();
startService(serviceIntent);
serviceIntent.putExtra(number, pnumber);
break;
}
}
}
}
And then in my other Activity:
Bundle extras = this.getIntent().getExtras(); {
if(extras !=null)
{
String newnumber = extras.getString(number,pnumber);
Uri number = Uri.parse(newnumber);
Intent callIntent = new Intent(Intent.ACTION_CALL, number);
Intent textIntent = new Intent(Intent.ACTION_SENDTO, number);
}
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.button2:
//Log.d(TAG, "onClick: starting call");
startActivity(callIntent);
break;
case R.id.button3:
//Log.d(TAG, "onClick: start text message");
startActivity(textIntent);
break;
}
}
}
The Uri keeps parsing "newnumber" and giving a phone number made from the numbers that have those letters (For example, I would get 639686237 since n is on the 6 key, e is on the 3 key etc.) It also doesn't recognize the variables number and pnumber.