package com.test.intentdemo;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
private Button btn=null;
public void onCreate(Bundle savedInstanceState)//onCreate方法用来初始化Activity实例对象
{
super.onCreate(savedInstanceState);//super.onCreate(savedInstanceState)的作用是调用其父类Activity的onCreate方法来实现对界面的图画绘制工作
setContentView(R.layout.activity_main);//setContentView(R.layout.main)的作用是加载一个界面
btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(listener);
}
private View.OnClickListener listener=new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent=new Intent();
intent.setAction(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:5554"));
intent.putExtra("sms_body", "Hello!");//sms_body不能随意换成其他
startActivity(intent);
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}