开发者

On Nexus ONE, getting RESULT_ERROR_GENERIC_FAILURE when trying to use SmsManager.sendTextMessage()

开发者 https://www.devze.com 2022-12-24 15:36 出处:网络
I\'ve been successfully testing my app which sends a text message to another phone number.The problem came w开发者_C百科hen I sent this to a buddy that has the Nexus One.I added a pending intent to se

I've been successfully testing my app which sends a text message to another phone number. The problem came w开发者_C百科hen I sent this to a buddy that has the Nexus One. I added a pending intent to sendTextMessage() and saw I'm hitting: RESULT_ERROR_GENERIC_FAILURE.


Generic Error is non specific error, sometimes it is shown if our Network provider don't send sms on non existing numbers, I have found this after research, I have 2 androids, both are from different Providers, one provider sends Message on non existing phone numbers, so I am not facing Generic Error Problem in this sim, on the other hand the 2nd Network Provider Don't sends the message on non existing phone number, so the generic error is appear in this Case. Guys kindly check your Programs with other Networks, May be It solves your Problem. thanks.


Mi problem is the same and how Jonathan Akers said, the RESULT_ERROR_GENERIC_FAILURE, is triggered by the sender mobile (Nexus One) to any other, so, nothing sms message is send use this mobile phone by programmatically mode without use intent sms messaging.

All works fine using two android emulators.

I use BroadcastReceiver for listen sms events like as:

public class 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()));
        }
    }

}
`

And for send sms message i use this PendingInents how has been put at the application launch, my logs said that all was right except for this, that launch the RESULT_ERROR_GENERIC_FAILURE flag. 
The code is:

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

And that is all i don't have idea that is for my mobile phone or anything, how i said all works fine using two android emulators, Activity.RESULT_OK is launched and the sms message is received for the listen emulator.

Thanks for all!!

0

精彩评论

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