-4
<TextView
    android:id="@+id/TextView03"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/header"
    android:layout_alignLeft="@+id/button1"
    android:layout_marginBottom="127dp"
    android:text="@string/phone"
    android:textColor="#000000"
    android:textSize="12dp"
    android:typeface="sans" />

電話情報を保持するテストビューがあります。メッセージをクリックしてデフォルトの電話ボックスを開くにはどうすればよいですか。

<string name="email">Phone: 1-866-232-3805</string>

これが私のオーバーライドメソッドです。

    @Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView t2 = (TextView) findViewById(R.id.TextView03);
            email.setOnClickListener(new View.OnClickListener() {

                 public void onClick(View v) {
                     // TODO Auto-generated method stub                
                 }

           });
}

ここからどうすればいいですか?

4

4 に答える 4

2

textviewのonclicklistenerでこのコードを使用します

 Intent callIntent = new Intent(Intent.ACTION_DIAL);

            callIntent.setData(Uri.parse("tel:"+t2.getText()));
            startActivity(callIntent);

また、マニフェストファイルに次の権限を追加します

 <
uses-permission android:name="android.permission.CALL_PRIVILEGED" />
  <uses-permission android:name="android.permission.CALL_PHONE" />
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
于 2012-10-18T12:21:30.687 に答える
2

最初に string.xml から番号を取得してから、そのIntent.ACTION_DIAL番号で電話をかける必要があります。

String phone = getResources().getString(R.string.email).split(":")[1];
        Intent DialIntent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+phone));
        DialIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(DialIntent);
于 2012-10-18T12:22:33.290 に答える
2

ダイヤラーを開きたいだけなら

Button contactsButton = (Button) findViewById(R.id.contacts_button);
        contactsButton.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                Intent myIntent = new Intent(Intent.ACTION_DIAL);
                startActivity(myIntent);
            }
        });

指定した番号でダイヤラーを開きたい場合

Button contactsButton = (Button) findViewById(R.id.contacts_button);
        contactsButton.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {

                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:" +Call_number));
                startActivity(callIntent);

            }
        });
于 2012-10-18T12:24:04.473 に答える
1

コールダイヤルを表示する以下のインテントを使用します。

 Intent dial = new Intent();
 dial.setAction("android.intent.action.DIAL");
 dial.setData(Uri.parse("tel:"+ Phone));
 startActivity(dial); 

どこPhoneに電話したい電話番号です。

于 2012-10-18T12:22:15.490 に答える