Accessing the Dialer
This is how easy it is to activate the Android dialer:
startActivity(new Intent(ACTION_DIAL, Uri.parse("tel:6365551212")));
And here is a complete Activity
that shows the code in context. Specifically, this code:
- Creates a screen (an “Activity”) with a button
- Registers a listener with the button
- When you click the button, it starts the dialer
- When dialing completes, the user returns to this screen
public class DialerDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button dialButton = (Button) findViewById(R.id.dial_button); dialButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialPhone(); } }); } private void dialPhone() { Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri .parse("tel:6365551212")); startActivity(dialIntent); } }
When you run this you see a button:
Clicking the button brings up the dialer, with the number pre-typed:
Then you hit the green phone button to make the call:
Making the Call
You can also write code that actually makes the phone call using the ACTION_CALL intent. For that to work, your manifest needs to include the CALL_PHONE permission.
Perhaps you could use this feature to keep track of your kids. If they venture too many miles away from home, you could have their phone automatically dial home.