2012-10-18 37 views
-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" /> 

我有一个测试视图,它包含我的手机信息。如何在点击消息时打开默认电话消息框。Android:打开默认的手机损耗

<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     
       } 

      }); 
} 

我应该从这里做什么?

+0

你的意思是手机默认拨号器? – juned

+0

@juned:是的,点击这个号码,我需要打电话给这个号码。 – theJava

回答

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); 
2

使用此代码onclicklistener的TextView的

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" /> 
1

使用下面的意图,显示了CALL DIAL:

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

其中Phone是你想拨打的电话号码。

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); 
      } 
     }); 
如果你想打开拨号器指定nunber

然后

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); 

      } 
     });