Jordane
Jordane

Reputation: 643

Use phone number outside the app?

I don't know if it's possible but in my app I got an activity that show a phone number (retrieve from the web). Can I send this number to the main phone app of android? For example to call it or save it?

Upvotes: 0

Views: 82

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006614

You can create a tel:... Uri, where the ... is replaced by your phone number, then use that Uri with ACTION_DIAL or ACTION_CALL. For example:

package com.commonsware.android.dialer;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class DialerDemo extends Activity {
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
  }

  public void dial(View v) {
    EditText number=(EditText)findViewById(R.id.number);
    String toDial="tel:"+number.getText().toString();

    startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(toDial)));
  }
}

The code shown above is from this sample project.

Upvotes: 1

Related Questions