package com.example.administrator.mysend;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.ArrayList;
public class MainActivity extends Activity
private EditText et_num;
private EditText et_content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mysend_layout);
}
public void send(){
et_num= (EditText) findViewById(R.id.et_num);
et_content= (EditText) findViewById(R.id.et_msg);
String num=et_num.getText().toString();
String content=et_content.getText().toString();
//1、获得短信管理器
SmsManager sm=SmsManager.getDefault();
//2、切割短信,把长短信切割成多条小短信
ArrayList<String> smss=sm.divideMessage(content);
//3、把多条短信发送出去
for (String smss_divide:smss) {
sm.sendTextMessage(num,null,smss_divide,null,null);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@android:style/Theme.Light">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et_num"
android:hint="请输入手机号码"
android:textSize="30dp"
android:inputType="number"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et_msg"
android:textSize="30dp"
android:hint="请输入短信内容"
android:lines="3"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bt_send"
android:onClick="send"
android:textSize="30dp"
android:text="发送"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.administrator.mysend"
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
<activity
android:name=".MainActivity"
android:label="@string/app_name"
<intent-filter>
<action android:name="android.intent.action.MAIN"
<category android:name="android.intent.category.LAUNCHER"
</intent-filter>
</activity>
</application>
</manifest>