public class Activity_life extends Activity implements View.OnClickListener
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_life);
}
@Override
public void onClick(View view)
{
switch (view.getId())
{
case R.id.call:
{
String num = "18112341234";
Intent intentCall = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + num));
startActivity(intentCall);
break;
}
case R.id.sendMsg:
{
String number = "18112341234";
Intent intentSendMsg = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + number));
intentSendMsg.putExtra("sms_body", "你好");
startActivity(intentSendMsg);
break;
}
case R.id.photo:
{
Intent intentPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(intentPhoto);
break;
}
case R.id.share:
{
Intent intentShare = new Intent();
intentShare.setAction(Intent.ACTION_SEND);
intentShare.setType("text/plain");
intentShare.putExtra(Intent.EXTRA_TEXT, "好的好的!");
startActivity(intentShare);
break;
}
}
}
}
//activity_life.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/call"
android:text="打电话"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClick"
/>
<Button
android:id="@+id/sendMsg"
android:text="发短信"
android:onClick="onClick"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/photo"
android:text="拍照"
android:onClick="onClick"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/share"
android:text="分享"
android:onClick="onClick"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>