Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.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
Android 为什么我会得到;“一般故障”;发送短信时出错?_Android_Sms_Broadcastreceiver - Fatal编程技术网

Android 为什么我会得到;“一般故障”;发送短信时出错?

Android 为什么我会得到;“一般故障”;发送短信时出错?,android,sms,broadcastreceiver,Android,Sms,Broadcastreceiver,我正在从事android项目,我需要发送短信息。我的应用程序通过使用web服务收集所需信息,该信息非常短且纯文本。然后以短信的形式发送该信息 我使用了广播接收器,它将跟踪SMS是否成功发送,只需添加一个日志条目。我使用了smsmsmanager发送短信 我的设备具有很好的WiFi强度和良好的GPRS网络。在发送短信时,我发现广播接收器插入了日志条目,有些表示“成功”,有些表示“一般失败” 为什么很少有短信因为“一般故障”而失败?这背后的原因是什么 我在谷歌上搜索了一下,发现有些人说要关掉WiFi

我正在从事android项目,我需要发送短信息。我的应用程序通过使用web服务收集所需信息,该信息非常短且纯文本。然后以短信的形式发送该信息

我使用了广播接收器,它将跟踪SMS是否成功发送,只需添加一个日志条目。我使用了smsmsmanager发送短信

我的设备具有很好的WiFi强度和良好的GPRS网络。在发送短信时,我发现广播接收器插入了日志条目,有些表示“成功”,有些表示“一般失败”

为什么很少有短信因为“一般故障”而失败?这背后的原因是什么

我在谷歌上搜索了一下,发现有些人说要关掉WiFi。但对于使用网络服务,我需要打开WiFi


有人能对此给出一些见解吗?有解决此问题的方法吗?

在AndroidManifest文件中添加此权限

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

如果您同时发送大量短信息,它将淹没您的手机,因此最好有一些延迟

接下来,如果您确实延迟了,您必须确保它没有在UI线程中完成,否则您将得到ANR

尝试使用处理程序,我的朋友建议这样做,我尝试过,效果很好

至于一般问题,我不确定。。通用名称听起来像是正常的网络错误


希望这些信息有用。

我已经克服了这个通用故障消息,借助时间延迟将一个设备发送到多个号码,它几乎消除了通用故障

for(int index=0; index < phone.length; index++){
             phonenumber=phone[index];
            Toast.makeText(cxt, "Phone number is: "+phonenumber, Toast.LENGTH_LONG).show();
            if(index==0){
                Send_SMS(phonenumber.toString().trim(), textmessage);
            }
            else{
                new Handler().postDelayed(new Runnable() {
                    public void run() {

                        Send_SMS(phonenumber.toString().trim(), textmessage);
                    }
                }, 1000*40);
            }
        }

public void Send_SMS(String phonenumber, String message){

    // here you use sms manager to send the sms
}
for(int index=0;index
试试这个:

String [] cellArray = phNumbers.getText().toString().split(";");

mMessageSentCount = 0;

String cellno = cellArray[mMessageSentCount].toString().trim();         

startSendMessages(cellno);


private void startSendMessages(String ph){
    registerBroadCastReceivers();
    sendSMS(ph, mBody);
}
private void sendNextMessage(int mMessageSentCount){
    String ph = cellArray[mMessageSentCount].toString().trim();
    sendSMS(ph, mBody);     
}

private boolean thereAreSmsToSend(){
    return mMessageSentCount < cellArray.length;
}

private void sendSMS(final String phoneNumber, String message) {
    Toast.makeText(getBaseContext(), "Phone number is: "+phoneNumber, Toast.LENGTH_SHORT).show();
    String SENT = "SMS_SENT";
    String DELIVERED = "SMS_DELIVERED";

    SmsManager sms = SmsManager.getDefault();
    ArrayList<String> parts = sms.divideMessage(message);
    mMessageSentTotalParts = parts.size();

    Log.i("Message Count", "Message Count: " + mMessageSentTotalParts);

    ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
    ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();

    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
    PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);

    for (int j = 0; j < mMessageSentTotalParts; j++) {
        sentIntents.add(sentPI);
        deliveryIntents.add(deliveredPI);
    }

    mMessageSentParts = 0;
    sms.sendMultipartTextMessage(phoneNumber, null, parts, sentIntents, deliveryIntents);
}

private void registerBroadCastReceivers(){

    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode()) {
            case Activity.RESULT_OK:

                mMessageSentParts++;
                if ( mMessageSentParts == mMessageSentTotalParts ) {
                    mMessageSentCount++;
                    if(thereAreSmsToSend()){
                        sendNextMessage(mMessageSentCount);                         
                    } else{
                        Toast.makeText(getBaseContext(), "All SMS have been sent",Toast.LENGTH_SHORT).show();
                    }
                }

                Toast.makeText(getBaseContext(), "SMS sent",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                Toast.makeText(getBaseContext(), "Generic failure",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NO_SERVICE:
                Toast.makeText(getBaseContext(), "No service",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NULL_PDU:
                Toast.makeText(getBaseContext(), "Null PDU",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_RADIO_OFF:
                Toast.makeText(getBaseContext(), "Radio off",
                        Toast.LENGTH_SHORT).show();
                break;
            }
        }
    }, new IntentFilter(SENT));

    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode()) {

            case Activity.RESULT_OK:
                Toast.makeText(getBaseContext(), "SMS delivered",
                        Toast.LENGTH_SHORT).show();
                break;
            case Activity.RESULT_CANCELED:
                Toast.makeText(getBaseContext(), "SMS not delivered",
                        Toast.LENGTH_SHORT).show();
                break;
            }
        }
    }, new IntentFilter(DELIVERED));
}
String[]ray=phNumbers.getText().toString().split(“;”);
mMessageSentCount=0;
字符串cellno=CellRay[mMessageSentCount].toString().trim();
startSendMessages(cellno);
私有void startSendMessages(字符串ph){
注册受托人();
sendSMS(ph,mBody);
}
私有void sendNextMessage(int-mMessageSentCount){
字符串ph=X[mMessageSentCount].toString().trim();
sendSMS(ph,mBody);
}
私有布尔therearesmtosend(){
返回mmessagencentcount