sending sms

Put your problem here if it does not fit any of the other categories.

sending sms

Postby chouman » Thu Sep 18, 2008 12:15 am

having a little problem sending sms messages. Here is my code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public static void sendSMS(String phoneNumber, String text)
  2.         {
  3.                 SmsManager smsManager = SmsManager.getDefault();
  4.                 List<String> dividedMessages;
  5.                
  6.                 //break the message apart if it's longer than 160 characters
  7.                 if(text.length() > 160)
  8.                 {
  9.                         dividedMessages = smsManager.divideMessage(text);
  10.                         for(String partialText : dividedMessages)
  11.                                 smsManager.sendTextMessage(phoneNumber, null, partialText, null, null);
  12.                 }
  13.                 else
  14.                         smsManager.sendTextMessage(phoneNumber, null, text, null, null);
  15.         }
  16.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


and this is what i got from logcat:

W/dalvikvm( 3886): threadid=3: thread exiting with uncaught exception (group=0x40010e28)
E/AndroidRuntime( 3886): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 3886): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.asurion.android.activity
/com.asurion.android.activity.AddressBook}: java.lang.NullPointerException
E/AndroidRuntime( 3886): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2131)
E/AndroidRuntime( 3886): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2147)
E/AndroidRuntime( 3886): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
E/AndroidRuntime( 3886): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
E/AndroidRuntime( 3886): at android.os.Handler.dispatchMessage(Handler.java:88)
E/AndroidRuntime( 3886): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 3886): at android.app.ActivityThread.main(ActivityThread.java:3708)
E/AndroidRuntime( 3886): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3886): at java.lang.reflect.Method.invoke(Method.java:492)
E/AndroidRuntime( 3886): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:734)
E/AndroidRuntime( 3886): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:492)
E/AndroidRuntime( 3886): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3886): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 3886): at android.os.Parcel.readException(Parcel.java:1072)
E/AndroidRuntime( 3886): at android.os.Parcel.readException(Parcel.java:1054)
E/AndroidRuntime( 3886): at com.android.internal.telephony.gsm.ISms$Stub$Proxy.sendRawPdu(ISms.java:286)
E/AndroidRuntime( 3886): at android.telephony.gsm.SmsManager.sendRawPdu(SmsManager.java:245)
E/AndroidRuntime( 3886): at android.telephony.gsm.SmsManager.sendTextMessage(SmsManager.java:78)
E/AndroidRuntime( 3886): at com.asurion.android.util.ExternalServices.sendSMS(ExternalServices.java:79)
E/AndroidRuntime( 3886): at com.asurion.android.activity.AddressBook.initialize(AddressBook.java:391)
E/AndroidRuntime( 3886): at com.asurion.android.activity.ContactListAbstract.onCreate(ContactListAbstract.java:15
0)
E/AndroidRuntime( 3886): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1121)
E/AndroidRuntime( 3886): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2094)
chouman
Developer
Developer
 
Posts: 27
Joined: Thu Jan 03, 2008 2:59 pm

Top

Postby plusminus » Thu Sep 18, 2008 3:38 am

Hello chouman,

Did you add the SEND_SMS permission :?:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <uses-permission android:name="android.permission.SEND_SMS" />
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Also, maybe add a dummy PendingIntent as the fourth parameter, like:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(), 0);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby chouman » Thu Sep 18, 2008 6:00 pm

yea i added the permission. It seems like the problem was the pendingintent for the 4th parameter. it's kind of weird that null is not allowed. weird
chouman
Developer
Developer
 
Posts: 27
Joined: Thu Jan 03, 2008 2:59 pm

Postby plusminus » Thu Sep 18, 2008 8:05 pm

I think I saw somewhere that null should be allowed, but that it is currently not working is said to be a bug. :P
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby soniya » Sat Oct 11, 2008 4:32 pm

how to simulate outgoing sms???plz help out..
soniya
Senior Developer
Senior Developer
 
Posts: 111
Joined: Mon Jan 14, 2008 1:52 pm
Location: india

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests