0

实际上我的概念是使用 android 应用程序代码消息必须发送一个特定的数字。我的代码是

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    buttonSend = (Button) findViewById(R.id.buttonSend);
    textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo);
    textSMS = (EditText) findViewById(R.id.editTextSMS);

    buttonSend.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            String phoneNo = textPhoneNo.getText().toString();
            String sms = textSMS.getText().toString();

            try {
                SmsManager smsManager = SmsManager.getDefault();
                smsManager.sendTextMessage(phoneNo, null, sms, null, null);
                String smsNumber = textPhoneNo.getText().toString();
                  String smsText = textSMS.getText().toString();
                  smsManager.sendTextMessage(smsNumber, null, smsText, null, null);
                Toast.makeText(getApplicationContext(), "SMS Sent!",
                        Toast.LENGTH_LONG).show();
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "SMS faild, please try again later!",
                        Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }
    });
}
4

1 回答 1

1

AndroidManifest.xml 文件中所需的权限:

<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>  
于 2012-07-20T11:56:22.023 回答