Activity活动类:

package com.example.intentdemo;
import …………
public class MainActivity extends Activity {
private Button btn = null;
private Button btn2 = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.mainBtn);
btn.setOnClickListener(listener);
btn2 = (Button) findViewById(R.id.mainBtn2);
btn2.setOnClickListener(listener2);
}
private OnClickListener listener = new OnClickListener() {

@Override
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:5554"));
startActivity(intent);
}
};
private OnClickListener listener2 = new OnClickListener() {

@Override
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:5554"));
intent.putExtra("sms_body", "Welcome to ......");
startActivity(intent);
}
};
}


layout布局:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
………… >
<Button
android:id="@+id/mainBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="call"/>
<Button
android:id="@+id/mainBtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send"/>
</LinearLayout>


Manifest文件配置:


在<application></application>标签的外部添加


<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.SEND_SMS"/>