Reputation: 19733
I am using SmsManager to send text messages from my application. The code snippet is
smsManager.sendTextMessage(number, null, content, null, null);
For messages with less than 160 characters. And for multipart messages I use,
ArrayList<String> parts = smsManager.divideMessage(content);
sMan.sendMultipartTextMessage(number, null, parts, null, null);
These statements cause The process com.android.phone has stopped unexpectedly please try again in a random fashion. I don't understand what's going on.
This is the stack trace I got:
java.lang.NullPointerException
E/AndroidRuntime( 1143): at com.android.internal.telephony.SMSDispatcher.handleSendComplete(SMSDispatcher.java:741)
E/AndroidRuntime( 1143): at com.android.internal.telephony.SMSDispatcher.handleMessage(SMSDispatcher.java:407)
E/AndroidRuntime( 1143): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1143): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1143): at android.app.ActivityThread.main(ActivityThread.java:4603)
E/AndroidRuntime( 1143): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1143): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 1143): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 1143): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 1143): at dalvik.system.NativeStart.main(Native Method)
Any pointers will be greatly appreciated.
Upvotes: 1
Views: 993
Reputation: 19733
smsManager.sendTextMessage(number, null, content, null, null);
Technically the null parameters for the sentIntent and deliveredIntent shouldn't cause any problems. But that's not the case with my application. I have seen many applications in the Android market with the same issue and users giving them 1 star rating. I repaced the null parameters with insignificant intents and now don't have trouble using them.
PendingIntent sent = PendingIntent.getBroadcast(context, 0, new Intent(), 0);
PendingIntent delivered = PendingIntent.getBroadcast(context, 0, new Intent(), 0);
smsManager.sendTextMessage(number, null, content, sent, delivered);
Now the code works fine.
Upvotes: 2