Android send SMS automatically on button click

后端 未结 5 1657
孤独总比滥情好
孤独总比滥情好 2020-12-24 04:01

I am trying to automatically send SMS message to a certain number when the user presses a button on the screen.

This is my code:

Intent smsIntent = n         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 04:27

    You can use the build in Intent also:

     buttonSendSms_intent.setOnClickListener(new Button.OnClickListener(){
    
           @Override
           public void onClick(View arg0) {
            // TODO Auto-generated method stub
    
            String smsNumber = edittextSmsNumber.getText().toString();
            String smsText = edittextSmsText.getText().toString();
    
            Uri uri = Uri.parse("smsto:" + smsNumber);
            Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
            intent.putExtra("sms_body", smsText);  
            startActivity(intent);
           }});
    

提交回复
热议问题