1>短信发送器。开始还是设计界面。go
<?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:id="@+id/mobile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/mobile"
/>
<EditText
android:id="@+id/mobileText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/messageText"
/>
<EditText
android:id="@+id/messageText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minLines="3"
/>
<Button
android:id="@+id/sendBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sendBtn"
/>
</LinearLayout>
2>然后换个图标再然后 别忘了,要用发送短信功能要加,权限。
<uses-permission android:name="android.permission.SEND_SMS"/>
3>写Activity。
package com.duantl.sms;
import java.util.ArrayList;
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 SmsActivity extends Activity {
/** Called when the activity is first created. */
private EditText mobileTxt = null;
private EditText messageTxt = null;
private Button sendBtn = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mobileTxt = (EditText)this.findViewById(R.id.mobileText);
messageTxt = (EditText)this.findViewById(R.id.messageText);
sendBtn = (Button)this.findViewById(R.id.sendBtn);
sendBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//获得文本内容
String mobileStr = mobileTxt.getText().toString();
String messageStr = messageTxt.getText().toString();
//发短信
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> smsStr = smsManager.divideMessage(messageStr);
for (String text : smsStr) {
smsManager.sendTextMessage(mobileStr, null, text, null, null);
}
Toast.makeText(SmsActivity.this, R.string.sendSu, Toast.LENGTH_LONG).show();
}
});
}
}
上个效果图