package com.jsjrjsb1504.sdut.testdemo
import android.app.PendingIntent
import android.content.Intent
import android.support.v7.app.AppCompatActivity
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 MainActivity extends AppCompatActivity {
EditText number,content
SmsManager smsManager
Button send
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//获取smsManager
smsManager = smsManager.getDefault()
//获取程序界面从两个文本框和按钮
number = findViewById(R.id.number)
content = findViewById(R.id.content)
send = findViewById(R.id.send)
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//创建一个PendingIntent 对象
PendingIntent pi = PendingIntent.getActivity(MainActivity.this,0,new Intent(),0)
smsManager.sendTextMessage(number.getText().toString(),null,content.getText().toString(),pi,null)
//提示短信发送成功
Toast.makeText(MainActivity.this,"短信发送成功",Toast.LENGTH_LONG).show()
}
})
}
}