发送短信的申请不起作用

时间:2011-07-27 21:48:45

标签: android button sms

我正在尝试创建一个可以发送短信的应用程序,以及makin调用(创建USSD代码)并且我有问题。我只是无法发送短信工作。我的应用总是强行关闭。你能帮我吗。这是我的代码,它的一部分,并且在标记的位置,我需要在按下按钮时发送SMS并且语句是正确的。请帮忙。

public class Stanje extends Activity {
    private EditText text;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        text = (EditText) findViewById(R.id.editText1);

    }

    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }



    public void myClickHandler(View view) {
        CheckBox TmobileBox = (CheckBox) findViewById(R.id.checkBox1);
        CheckBox Tmobile2Box = (CheckBox) findViewById(R.id.checkBox2);
        CheckBox BonbonBox = (CheckBox) findViewById(R.id.checkBox3);
        String encodedHash = Uri.encode("#");
        text = (EditText) findViewById(R.id.editText1);
        long inputValue1 = Long.parseLong(text.getText().toString());

        switch (view.getId()) {
        case R.id.button1:

            if(TmobileBox.isChecked()== true && Tmobile2Box.isChecked()== false &&
                           BonbonBox.isChecked()==false ){

    ******When this button is pressed, and first checkbox i checked, I need to send an SMS "S" to
           number 3636******

            }else if (TmobileBox.isChecked()== false && Tmobile2Box.isChecked()== true 
                          && BonbonBox.isChecked()==false) {


                startActivity(new Intent("android.intent.action.CALL",
                    Uri.parse("tel:*100" + encodedHash)));

            }else if (TmobileBox.isChecked()== false && Tmobile2Box.isChecked()== false 
                          && BonbonBox.isChecked()==true) {


                startActivity(new Intent("android.intent.action.CALL",
                    Uri.parse("tel:*100" + encodedHash)));


            }else{

                Toast.makeText(getApplicationContext(), "Odaberi svog operatera! 
                                  (Samo jednog)", Toast.LENGTH_SHORT).show();   
            }

            break;

        case R.id.button2:

            if(TmobileBox.isChecked()== true && Tmobile2Box.isChecked()== false && 
                    BonbonBox.isChecked()==false ){

    ******When this button is pressed, and first checkbox i checked, I need to send an SMS "A" to
           number 0977******    

            }else if (TmobileBox.isChecked()== false && Tmobile2Box.isChecked()== true 
                         && BonbonBox.isChecked()==false) {

    ******When this button is pressed, and first checkbox i checked, I need to send an SMS "STANJE" 
           to number 700******


            }else if (TmobileBox.isChecked()== false && Tmobile2Box.isChecked()== false 
                         && BonbonBox.isChecked()==true) {


            }else{

                Toast.makeText(getApplicationContext(), "Odaberi svog operatera! 
                                (Samo jednog)", Toast.LENGTH_SHORT).show(); 
            }

            break;



        }
    }
}

1 个答案:

答案 0 :(得分:1)

您是否有权在您的清单中发送短信?

<uses-permission android:name="android.permission.SEND_SMS">

建议: 为什么不削减实现RadioGroup的代码长度?它将削减代码长度......