Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 由于某些原因,第一次未发送短信时,请尝试再次发送短信_Java_Android - Fatal编程技术网

Java 由于某些原因,第一次未发送短信时,请尝试再次发送短信

Java 由于某些原因,第一次未发送短信时,请尝试再次发送短信,java,android,Java,Android,我是androi的新来者。我的问题是以下我有一个代码,发送短信的权利,但我想能够做到这一点时,发送的消息失败自动尝试再次发送约3次,如果它没有发送,因为它没有做任何事情。 你好,我希望你能帮我解决这个问题,我玩得很开心 这里我留下密码 public class Principal extends Activity { EditText txtPhone; EditText txtMsg; Button btnSend; TextView msj; @Override protected vo

我是androi的新来者。我的问题是以下我有一个代码,发送短信的权利,但我想能够做到这一点时,发送的消息失败自动尝试再次发送约3次,如果它没有发送,因为它没有做任何事情。 你好,我希望你能帮我解决这个问题,我玩得很开心

这里我留下密码

public class Principal extends Activity {

EditText txtPhone;
EditText txtMsg;
Button btnSend;
TextView msj;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_principal);

    txtPhone = ((EditText)findViewById(R.id.txtPhone ));
    txtMsg = ((EditText)findViewById(R.id.txtMsg ));
    btnSend = ((Button)findViewById(R.id.btnSend ));
    msj = ((TextView)findViewById(R.id.txtmsj));

    btnSend.setOnClickListener(
            new View.OnClickListener() {
                public void onClick(View view) {

                    PendingIntent sentIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent("SMS_SENT"), 0);

                    registerReceiver(new BroadcastReceiver() {

                        @Override
                        public void onReceive(Context context, Intent intent) {
                            switch (getResultCode()){

                                case Activity.RESULT_OK:
                                    msj.setText("SMS SENT");

                                    break;
                                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                                    msj.setText("I can not send SMS");

                                    break;
                                case SmsManager.RESULT_ERROR_NO_SERVICE:
                                    msj.setText("service not available");

                                    break;
                                case SmsManager.RESULT_ERROR_NULL_PDU:
                                    msj.setText("PDU (Protocol Data Unit) es NULL");

                                    break;
                                case SmsManager.RESULT_ERROR_RADIO_OFF:
                                    msj.setText("turn on the radio");
                                               break;

                            }
                        }
                    }, new IntentFilter("SMS_SENT"));

                    SmsManager sms = SmsManager.getDefault();
                    if( txtPhone.getText().toString().length()> 0 &&
                            txtMsg.getText().toString().length()>0 )
                    {
                        sms.sendTextMessage( txtPhone.getText().toString() , null, txtMsg.getText().toString() , sentIntent, null);
                    }
                    else
                    {
                        Toast.makeText(getApplicationContext(), "Can not send, data is incorrect", Toast.LENGTH_SHORT).show();
                    }
                }
            });
}

请澄清您的具体问题或添加其他详细信息,以突出显示您所需的内容。正如目前所写的,很难说清楚你在问什么。好吧,对不起。就像使用该代码的应用程序一样,我发送普通的文本消息,然后添加一个号码和消息。发送时没有任何问题,但当我没有余额或网络出现问题时,在一切正常之前,它似乎不会发送。我想,当这种情况发生时,相同的应用程序尝试发送短信3次后,这些尝试,如果发送失败,它不做任何其他事情。我希望我已经解释过了,谢谢你的回复。