Android : Android Send SMS Error

on Saturday, September 27, 2014


I'm trying to send an SMS in Android to a specific number and port, using the following code:



final String SENT = "SMS_SENT";
PendingIntent sent = PendingIntent.getBroadcast(context, 0, new Intent(SENT), 0);

registerReceiver(Globals.smsReceiver, new IntentFilter(code));

SmsManager manager = SmsManager.getDefault();
manager.sendDataMessage(Globals.NUMBER, null, Globals.PORT, message.getBytes(), sent, null);


Globals.smsReceiver is a "SMSSentBroadcastReceiver" object, which is a subclass of "BroadcastReceiver". Globals.PORT is 5000.


However, when the code reaches onReceive() on SMSSentBroadcastReceiver, it receives a RESULT_ERROR_GENERIC_FAILURE code. According to the documentation, I checked for the "errorCode" in the sentIntent and it returned 42. What does this mean? What is happening and how can I send an SMS?


Also, this code worked before. It stopped working for no apparent reason, except for the fact that I changed the SIM Card on the mobile to a different number. But I checked that this card is enabled and can send "normal" SMS through the default SMS app.


Finally, my Manifest also has this:



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


And this:



<receiver android:name=".support.SMSSentBroadcastReceiver" >
<intent-filter>
<action android:name="SMS_SENT" />
</intent-filter>
</receiver>


How can I figure out what "42" errorCode is and what I can do about it?


Thanks in advance!


0 comments:

Post a Comment