作者:手机用户2602916235 | 来源:互联网 | 2023-07-23 16:44
一、项目结构二、activity_main.xml代码<LinearLayoutxmlns:android"http:schemas.android.comapkresa
一、项目结构
二、activity_main.xml代码
xmlns:tools="http://schemas.android.com/tools"
android:layout_
android:layout_
android:orientation="vertical"
>
android:id="@+id/et_phone"
android:layout_
android:layout_
android:hint="请输入号码"
android:inputType="phone"
/>
android:id="@+id/et_content"
android:layout_
android:layout_
android:lines="5"
android:hint="请输入内容"
android:text="oohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohoho"
android:gravity="top"
/>
三、MainActivity.java代码
package com.example.sendnote;
import java.util.ArrayList;
import android.support.v7.app.ActionBarActivity;
import android.telephony.SmsManager;
import android.util.Log;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends ActionBarActivity {
private static final String TAG="MainActivity";
private EditText phone;
private EditText content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phOne=(EditText)findViewById(R.id.et_phone);
cOntent=(EditText)findViewById(R.id.et_content);
}
public void send(View v){
String phOneText=phone.getText().toString();
String cOntentText=content.getText().toString();
Log.i(TAG, "发送号码:"+phoneText);
Log.i(TAG, "发送内容:"+contentText);
//直接使用短信api,进行发送
SmsManager sm=SmsManager.getDefault();
//如果短信过长,会导致短信不发送,在这先把短信内容处理为多个短信
ArrayList al=sm.divideMessage(contentText);
for (String string : al) {
sm.sendTextMessage(phoneText, null,string, null, null);
}
}
}
下载地址