1. 程式人生 > >8天學會android---簡訊傳送器

8天學會android---簡訊傳送器

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
number=(EditText) this.findViewById(R.id.number);
content=(EditText) this.findViewById(R.id.content);
send=(Button) this.findViewById(R.id.send);
send.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.send:
String phoneNumber=number.getText().toString().trim();
String phoneContent=content.getText().toString().trim();
SmsManager manager=SmsManager.getDefault();
ArrayList<String> texts=manager.divideMessage(phoneContent);
for(String text : texts){
manager.sendTextMessage(phoneNumber, null, text, null, null);
}
Toast.makeText(MainActivity.this, "傳送成功", Toast.LENGTH_SHORT).show();
break;
}
}
}