开发者

Aplication with sending SMS won't work

I am trying to make an Application, that is posible to send SMS, and makin calls ( geting USSD codes) And i have problem with that. I just can't get sending SMS working. My app always force closes. Can you help me please. This is my code, part of it, and in marked places i need to send SMS when button is pressed and statement is right. Please help.

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 (vie开发者_高级运维w.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;



        }
    }
}


Do you have permission in your Manifest to send sms?

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

Suggestion: Why dont you cut on code length implementing RadioGroup? It will cut on code length...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜