package com.example.sendsms;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.telephony.SmsManager;
public class MainActivity extends Activity {
EditText text1;
EditText text2;
Button btn1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text1 = (EditText)findViewById(R.id.number);
text2 = (EditText)findViewById(R.id.content);
btn1 = (Button)findViewById(R.id.send);
btn1.setOnClickListener(new ButtonClickListener());
}
private final class ButtonClickListener implements View.OnClickListener{
@Override
public void onClick(View v) {
String number = text1.getText().toString();
String content = text2.getText().toString();
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> texts = smsManager.divideMessage(content);
for (String s : texts){
smsManager.sendTextMessage(number, null, s, null, null);
}
Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG);
}
}
}
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.telephony.SmsManager;
public class MainActivity extends Activity {
EditText text1;
EditText text2;
Button btn1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text1 = (EditText)findViewById(R.id.number);
text2 = (EditText)findViewById(R.id.content);
btn1 = (Button)findViewById(R.id.send);
btn1.setOnClickListener(new ButtonClickListener());
}
private final class ButtonClickListener implements View.OnClickListener{
@Override
public void onClick(View v) {
String number = text1.getText().toString();
String content = text2.getText().toString();
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> texts = smsManager.divideMessage(content);
for (String s : texts){
smsManager.sendTextMessage(number, null, s, null, null);
}
Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG);
}
}
}