Android-从Android应用程序发送短信

时间:2016-04-06 16:21:09

标签: android

这是我的代码。我在清单文件中添加了权限,但不幸的是我的应用程序被停止了。为什么会这样? 如果我尝试捕获,那么捕捉部分就会被执行。

    import android.app.Activity;
    import android.os.Bundle;
    import android.telephony.SmsManager;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    public class SendSMSActivity extends Activity {
/** Called when the activity is first created. */
EditText eTextMsg, eTextMblNumber;
Button btnSendSMS;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    eTextMblNumber = (EditText) findViewById(R.id.etextMblNumber);
    eTextMsg = (EditText) findViewById(R.id.etextMsg);
    btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
    btnSendSMS.setOnClickListener(new OnClickListener()
    {
        public void onClick(View v) {
            // TODO Auto-generated method stub
            sendSMS();
        }
    });
}
public void sendSMS()
{
    SmsManager sm = SmsManager.getDefault();
    String number = eTextMblNumber.getText().toString();
    String msg = eTextMsg.getText().toString();
    sm.sendTextMessage(number, null, msg, null, null);
}

0 个答案:

没有答案