界面布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical“ android:layout_width="fill_parent“ android:layout_height="fill_parent" >
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="@string/inputmobile"/>
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="@+id/mobile"/>
<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/button"
android:id="@+id/button"/>
</LinearLayout>
发送短信Java代码:
SmsManager smsManager = SmsManager.getDefault();
PendingIntent sentIntent = PendingIntent.getBroadcast(SMSSender.this, 0, new Intent(), 0);
//如果字数超过70,需拆分成多条短信发送
List<String> msgs = smsManager.divideMessage(content);
for(String msg : msgs){
//最后二个参数为短信已发送的广播意图,最后一个参数为短信对方已收到短信的广播意图
smsManager.sendTextMessage(mobile, null, msg, sentIntent, null);
}
Toast.makeText(this, "短信发送完成", Toast.LENGTH_LONG).show();