<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 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/numberinput" /> <EditText android:id="@+id/number" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="number" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/contentsms" /> <EditText android:id="@+id/content" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minLines="3" android:inputType="text" /> <Button android:id="@+id/send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button" /> </LinearLayout>
package com.example.sms; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class SMSActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final EditText text01 = (EditText) this.findViewById(R.id.number); final EditText text02 = (EditText) this.findViewById(R.id.content); Button btnSend = (Button) this.findViewById(R.id.send); btnSend.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String mobile = text01.getText().toString(); String content = text02.getText().toString(); SmsManager smsManager = SmsManager.getDefault(); List<String> texts = smsManager.divideMessage(content); for (String text : texts) { smsManager.sendTextMessage(mobile, null, text, null, null); } Toast.makeText(SMSActivity.this, "success", Toast.LENGTH_LONG).show(); } }); } }