android学习笔记3--------短信发送器
效果图:import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SendMessageActivity extends Activity
{
private EditText mobileEditText;
private EditText contenText;
private Button sendbButton;
private Button exitButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mobileEditText=(EditText)findViewById(R.id.mobile);
contenText=(EditText)findViewById(R.id.content);
sendbButton=(Button)findViewById(R.id.send);
exitButton=(Button)findViewById(R.id.exit);
sendbButton.setOnClickListener(listener);
exitButton.setOnClickListener(listener);
}
private OnClickListener listener=new OnClickListener()
{
@Override
public void onClick(View v)
{
Button button=(Button)v;
switch (button.getId())
{
case R.id.send:
String mobile=mobileEditText.getText().toString();
String contentString=contenText.getText().toString();
SmsManager smsManager=SmsManager.getDefault();
//Intent intent=new Intent();
//intent.setAction(Intent.ACTION_SENDTO);
//intent.setData(Uri.parse("smsto:"+mobile));
if(contentString.length()>70)
{
List<String> contents=smsManager.divideMessage(contentString);
for(String sms:contents)
{
smsManager.sendTextMessage(mobile, null, sms, null, null);
//intent.putExtra("sms_body", sms);
//SendMessageActivity.this.startActivity(intent);
}
}
else
{
smsManager.sendTextMessage(mobile, null, contentString, null, null);
//intent.putExtra("sms_body", contentString);
//SendMessageActivity.this.startActivity(intent);
}
Toast.makeText(SendMessageActivity.this, "短信已发送", Toast.LENGTH_SHORT).show();
break;
case R.id.exit:
android.os.Process.killProcess(android.os.Process.myPid());
break;
default
补充:移动开发 , Android ,