Reputation: 125
hopefully I can get some help on an issue I have been having. I am using the "android.telephony.SmsManager" class to send a Data text message through calling API function: "sendDataMessage(...)" and each time the function is called, I get a null pointer exception. I have done my research, and found that this can be caused by trying to send too large of a data message (on the order of 133 bytes or more). I am sending 5 bytes - so I know I am not above the limit. I do not get the null pointer exception on the emulator (although I know there are other issues with the emulator not properly sending Data SMS messages, so perhaps I would get an error if the emulator worked). My code is as follows:
SmsManager sm = SmsManager.getDefault();
int SMS_PORT = 8091;
sm.sendDataMessage("5555551212", null, (short)SMS_PORT, "hello".getBytes(), null, null);
Per the API documentation, the 3 arguments that I have as "null" above are allowed to be null. I have also tried sending intents to the last 2 arguments, and a string in the 2nd argument, but still get the null pointer exception.
Note that I am getting this exception when I run on my android phone. I am running on gingerbread, and am using the correct API level for GB. My android manafest file does have the proper permissions to send an SMS.
A logcat of the null pointer exception is as follows:
E/AndroidRuntime( 1690): FATAL EXCEPTION: main
E/AndroidRuntime( 1690): java.lang.IllegalStateException: Could not execute method of the activity
E/AndroidRuntime( 1690): at android.view.View$1.onClick(View.java:2144)
E/AndroidRuntime( 1690): at android.view.View.performClick(View.java:2485)
E/AndroidRuntime( 1690): at android.view.View$PerformClick.run(View.java:9081)
E/AndroidRuntime( 1690): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 1690): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 1690): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 1690): at android.app.ActivityThread.main(ActivityThread.java:3686)
E/AndroidRuntime( 1690): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1690): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1690): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
E/AndroidRuntime( 1690): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
E/AndroidRuntime( 1690): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1690): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 1690): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1690): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1690): at android.view.View$1.onClick(View.java:2139)
E/AndroidRuntime( 1690): ... 11 more
E/AndroidRuntime( 1690): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 1690): at android.os.Parcel.readException(Parcel.java:1328)
E/AndroidRuntime( 1690): at android.os.Parcel.readException(Parcel.java:1276)
E/AndroidRuntime( 1690): at com.android.internal.telephony.ISms$Stub$Proxy.sendData(ISms.java:359)
E/AndroidRuntime( 1690): at android.telephony.SmsManager.sendDataMessage(SmsManager.java:212)
E/AndroidRuntime( 1690): at com.test.datasmstest.DataSMSTestActivity.DoClick(DataSMSTestActivity.java:55)
E/AndroidRuntime( 1690): ... 14 more
Any ideas - would any more information be useful to help solve this problem?
Thanks!
Upvotes: 1
Views: 1351
Reputation: 125
I have figured out what is going on - I am using a sprint handset and sprint does not allow data (binary) text messages. I know this because I took the same exact app that generated the above null pointer exception and ran it on a non-sprint handset (t-mobile in this case). The data text message was sent successfully. I had it addressed to a port on my sprint phone, and the t-mobile phone that sent the text message got the following text based message sent to it:
[Free Msg: Unable to send message to 15555551212. Please try again without a symbol in the text.]
15555551212 is where my sprint phone number would have been (hidden for obvious reasons).
So, it seems that the code above works perfectly well on some carrier handsets and not on others. I guess sprints implementation of android on my phone does not implement sendDataMessage properly (or purposely kills that function) such that it throws a null pointer exception.
Upvotes: 2