public class set_message extends Activity {
private EditText numberText;
private EditText contentText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.set_message);
numberText = (EditText) this.findViewById(R.id.number);
contentText = (EditText) this.findViewById(R.id.content);
Button button = (Button) this.findViewById(R.id.button);
button.setOnClickListener(new ButtonOnClickListener());
}
private final class ButtonOnClickListener implements View.OnClickListener{
@Override
public void onClick(View v) {
String number = numberText.getText().toString();
String content = contentText.getText().toString();
SmsManager manager = SmsManager.getDefault();//发送短信管理器
ArrayList<String> texts = manager.divideMessage(content);//短信字数判断,字数超过限制,拆分成几条短信
for(String text : texts){
manager.sendTextMessage(number, null, text, null, null);//发送短信 number 号码 : null 默认系统 : text 短信内容; null 有没有成功过发送;;null 对方是否收到短信 采用异步处理
}
Toast.makeText(set_message.this, R.string.sucsses, Toast.LENGTH_LONG).show();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/number"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/number"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/content"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minLines="3"
android:id="@+id/content"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set001"
android:id="@+id/button"
/>
</LinearLayo
ut>