在Nexus ONE上,尝试使用SmsManager.sendTextMessage()时获取RESULT_ERROR_GENERIC_FAILURE

时间:2010-03-27 01:12:31

标签: android

我已经成功测试了我的应用,该应用会向另一个电话号码发送短信。当我把它发送给有Nexus One的好友时,问题出现了。我为sendTextMessage()添加了一个待定的意图,看到我正在点击:RESULT_ERROR_GENERIC_FAILURE

2 个答案:

答案 0 :(得分:1)

  

通用错误是非特定错误,有时会显示我们的错误   我发现,网络提供商不会在非现有号码上发送短信   经过研究,我有2个机器人,两者都来自不同   提供商,一个提供商在不存在的电话号码上发送消息,   所以我在这个SIM卡中没有遇到通用错误问题   交出第二个网络提供商不要在不存在的情况下发送消息   电话号码,因此一般错误出现在此案例中。伙计们   检查您的程序与其他网络,可能它会解决您的问题   问题。感谢。

答案 1 :(得分:0)

Mi问题是相同的,Jonathan Akers如何说,RESULT_ERROR_GENERIC_FAILURE由发送方移动设备(Nexus One)触发到任何其他设备,因此,没有任何短信息发送使用此移动电话通过编程模式而不使用意图短信

使用两个Android模拟器,一切正常。

我使用BroadcastReceiver来监听sms事件,如:` 公共类ConfigSMS {

private static final String CLASS_NAME = "smsTestClass";

private static PendingIntent sentPI         =       null;
private static PendingIntent deliverPI      =       null;



//---------------       Getters & Setters       --------------------------//
public static PendingIntent getSentPI() {
    if (sentPI == null)
        initPI();
    return sentPI;
}
public static void setSentPI(PendingIntent sentPI) {
    ConfigSMS.sentPI = sentPI;
}

public static PendingIntent getDeliverPI() {
    if (deliverPI == null)
        initPI();
    return deliverPI;
}
public static void setDeliverPI(PendingIntent deliverPI) {
    ConfigSMS.deliverPI = deliverPI;
}
//------------------------------------------------------------------------//


/**
 * Initialize the Intents and BroadcastReceivers
 */
public static void initPI () {

    monitoringSMS();
}


/**
 * Create the inits and BroadcastReceivers for listen sms actions
 */
private static void monitoringSMS () {

    try {
        final String SENT_SMS_ACTION            =   "SENT_SMS_ACTION";
        final String DELIVERED_SMS_ACTION       =   "DELIVERED_SMS_ACTION";

        //Create the setIntent parameter
        Intent sentIntent = new Intent(SENT_SMS_ACTION);
        sentPI = PendingIntent.getBroadcast(
                ConfigAppValues.getContext(),
                0,
                sentIntent,
                0);

        //Create the deliveryIntetn parameter
        Intent deliveryIntent = new Intent(DELIVERED_SMS_ACTION);
        deliverPI = PendingIntent.getBroadcast(
                ConfigAppValues.getContext(),
                0,
                deliveryIntent,
                0);

        //Register the Broadcast Receivers
        ConfigAppValues.getContext().registerReceiver(new BroadcastReceiver() {

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

                switch (getResultCode()) {
                    case Activity.RESULT_OK:
                        Log.d(CLASS_NAME, "Successful transmission!!");
                        showNotificationToast("Successful transmission!!");
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Log.d(CLASS_NAME, "Nonspecific Failure!!");
                        showNotificationToast("Nonspecific Failure!!");
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Log.d(CLASS_NAME, "Radio is turned Off!!");
                        showNotificationToast("Nonspecific Failure!!");
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Log.d(CLASS_NAME, "PDU Failure");
                        showNotificationToast("PDU Failure");
                        break;
                }                   
            }
        }, new IntentFilter(SENT_SMS_ACTION));

        ConfigAppValues.getContext().registerReceiver(new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                // TODO Auto-generated method stub
                Log.d(CLASS_NAME, "The user have been receive the SMS message!!");

            }
        }, new IntentFilter(DELIVERED_SMS_ACTION));


    }catch (Exception e) {
        Log.e(CLASS_NAME, ExceptionUtils.exceptionTraceToString(
                e.toString(), 
                e.getStackTrace()));
    }
}

private static void showNotificationToast (String message) {

    try {

        //Show the toast message
        Toast.makeText(
                ConfigAppValues.getContext(),
                message,
                Toast.LENGTH_SHORT).show(); 

    }catch (Exception e) {
        Log.e(CLASS_NAME, ExceptionUtils.exceptionTraceToString(e.toString(), e.getStackTrace()));
    }
}

} `

对于发送sms消息,我使用这个PendingInents如何在应用程序启动时,我的日志说除了这一切都是正确的,启动RESULT_ERROR_GENERIC_FAILURE标志。 代码是:

SmsManager smsManager = SmsManager.getDefault();                                                                    


            Log.d(CLASS_NAME, "SmsText: " + smsText);
            //String test = "5556";
            smsManager.sendTextMessage(
                    receiver, 
                    null, 
                    smsText, 
                    ConfigSMS.getSentPI(), 
                    ConfigSMS.getDeliverPI());`

这就是我不知道那是针对我的手机还是其他任何东西,我怎么说使用两个Android模拟器都可以正常工作,Activity.RESULT_OK被启动并且收到了用于监听模拟器的sms消息。 / p>

谢谢大家!!