此代码不起作用。
我已包含<uses-permission android:name="android.permission.SEND_SMS"/>
在清单中。
public class MainActivity extends AppCompatActivity {
Button send;
EditText phoneNo;
EditText sms;
SmsManager smsManager;
void sendMe(View view){
sendMessage();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendMessage() {
phoneNo = (EditText) findViewById(R.id.PhoneNo);
sms = (EditText) findViewById(R.id.sms);
String Number = phoneNo.getText().toString();
String message = sms.getText().toString();
try {
smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(Number, "Number", message, null, null);
Toast.makeText(this,"SMS SEND", Toast.LENGTH_SHORT).show();
}catch(Exception e){
Toast.makeText(this, "SMS FAILED", Toast.LENGTH_SHORT).show();
}
}
}