2016-03-30 7 views
-2

Google Places APIを使用するアプリケーションを作成しました。場所をクリックすると、会社名、住所、番号がMainActivityに返されます。番号をクリックするとダイヤラーを開くことができますが、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); 

    } 

は、次のように感謝

マイコードがある数は、画面の一番下 enter image description here

+0

@MikeMを試してみてください。あなたは実際にどのような数字であってもかまいませんが、それは単なる一例であり、特定の番号を設定することはできません。 –

+0

あなたは 'onActivityResult()'に入っている 'formatted_phone_number'を使ってください。 –

答えて

9

この

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

これはありがとうございました –

+0

常にwc @CraigGallagher –

2

でこれを試してみてくださいされています。

String number = "494498498"; 
    Intent intent = new Intent(Intent.ACTION_DIAL); 
    intent.setData(Uri.parse("tel:" +number)); 
    startActivity(intent); 
+0

あなたは実際には1つの例にすぎないので、特定の数字を設定することはできません。 –

+0

@CraigGallagherはあなたの数値を数値Stringに渡すことはできません。これを行う際の問題は何ですか? –

+0

任意の番号を設定できます。あなたの番号をTextViewから取得し、intent.setData(Uri.parse( "tel:" + yourTextView.getText()。toString())のように設定します。 –

関連する問題