-2

I have made an application that uses Google Places API. Once I click on a place it returns the name of the company, the address and the number to the MainActivity. When I click on the number I can open the dialer but I can't seem to get the number that is returned on the MainActivity into the dialer. Any ideas on how I could go about doing this. Thanks

My Code is as follows

MainActivity

    private TextView mName;
    private TextView mAddress;
    private TextView mNumber;
  private static final LatLngBounds Sligo = new LatLngBounds(
            new LatLng(54.27, -8.47), new LatLng(54.27, -8.47));
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_main);
        mName = (TextView) findViewById(R.id.textView);
        mAddress = (TextView) findViewById(R.id.textView2);
        mAttributions = (TextView) findViewById(R.id.textView3);
        mNumber = (TextView) findViewById(R.id.textView4);
        Button pickerButton = (Button) findViewById(R.id.pickerButton);

        pickerButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                try {
                    PlacePicker.IntentBuilder intentBuilder =
                            new PlacePicker.IntentBuilder();
                    intentBuilder.setLatLngBounds(Sligo);


                    List<Integer> filterTypes = new ArrayList<Integer>();
                    filterTypes.add(Place.TYPE_CAR_REPAIR);


                    Intent intent = intentBuilder.build(MainActivity.this);
                    startActivityForResult(intent, PLACE_PICKER_REQUEST );
                } catch (GooglePlayServicesRepairableException
                        | GooglePlayServicesNotAvailableException e) {
                    e.printStackTrace();
                }
            }
        });
    @Override
    protected void onActivityResult(int requestCode,
                                    int resultCode, Intent data) {

        if (requestCode == PLACE_PICKER_REQUEST
                && resultCode == Activity.RESULT_OK) {

            final Place place = PlacePicker.getPlace(this, data);
            final CharSequence name = place.getName();
            final CharSequence address = place.getAddress();
            final CharSequence formatted_phone_number = place.getPhoneNumber();

            //    final CharSequence car = place.TYPE_CAR_REPAIR();
            //public abstract List<Integer> getTypeFilter(place.TYPE_CAR_REPAIR);
            String attributions = (String) place.getAttributions();
            if (attributions == null) {
                attributions = "";
            }

            mName.setText(name);
            mAddress.setText(address);
            mAttributions.setText(Html.fromHtml(attributions));
            mNumber.setText(formatted_phone_number);



        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }

onClick event

  public void onClickNumber(View arg)
    {
        Intent intent = new Intent(Intent.ACTION_DIAL);

        startActivity(intent);

    }

The number is at the bottom of the screen enter image description here

tak3shi
  • 2,305
  • 1
  • 20
  • 33
Craig Gallagher
  • 1,613
  • 6
  • 23
  • 52
  • @MikeM. You see the thing is it could really be any number that's just one example so I can't set a specific number. I can't find an answer that will bring me to the dialler with the number that I have selected – Craig Gallagher Mar 30 '16 at 12:46
  • Use `formatted_phone_number` you're getting in `onActivityResult()`. – Mike M. Mar 30 '16 at 12:48

2 Answers2

16

Try This

String phone = mNumber.getText().toString();
Intent phoneIntent = new Intent(Intent.ACTION_DIAL, Uri.fromParts(
"tel", phone, null));
startActivity(phoneIntent);
Abhishek Patel
  • 4,280
  • 1
  • 24
  • 38
3

Try this.

String number = "494498498";
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" +number));
startActivity(intent);
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
ak sacha
  • 2,149
  • 14
  • 19