如何在Android中使用选定号码在手机上打开拨号程序

如何在Android中使用选定号码在手机上打开拨号程序

本文介绍了如何在Android中使用选定号码在手机上打开拨号程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我制作了一个使用Google Places API的应用程序.一旦我单击一个位置,它就会将公司名称,地址和编号返回给MainActivity.当我单击该号码时,我可以打开拨号器,但是我似乎无法将MainActivity中返回的号码带到该拨号器中.关于如何执行此操作的任何想法.谢谢

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

我的代码如下

MainActivity

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事件

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

        startActivity(intent);

    }

数字在屏幕底部

推荐答案

尝试一下

String phone = mNumber.getText().toString();
Intent phoneIntent = new Intent(Intent.ACTION_DIAL, Uri.fromParts(
"tel", phone, null));
startActivity(phoneIntent);

这篇关于如何在Android中使用选定号码在手机上打开拨号程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:25