单击按钮后,我尝试将SMS发送到特定号码。但是,该应用程序始终发送一个Toast消息' SMS NOT SENT'当我点击应用程序中的按钮时。
我在清单文件中添加了SEND_SMS权限。
这是我的代码:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
}
public void OnClickStart(View view) {
String sms = "this is a message";
String phoneNo = "*******";
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS NOT SENT!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}