android - Send SMS from CDMA(htc evo) throws NullPointer Exception -
i doing 1 app in have send sms cdma phones throws null pointer exception. using
smsmanager.senddatamessage(phonenumber, null, (short)1001, msgstr.getbytes(), sentpi, deliveredpi);
it throws error below:-
07-21 14:53:26.875: error/androidruntime(8645): fatal exception: main 07-21 14:53:26.875: error/androidruntime(8645): java.lang.nullpointerexception 07-21 14:53:26.875: error/androidruntime(8645): @ android.os.parcel.readexception(parcel.java:1253) 07-21 14:53:26.875: error/androidruntime(8645): @ android.os.parcel.readexception(parcel.java:1235) 07-21 14:53:26.875: error/androidruntime(8645): @ com.android.internal.telephony.isms$stub$proxy.senddata(isms.java:558) 07-21 14:53:26.875: error/androidruntime(8645): @ android.telephony.smsmanager.senddatamessage(smsmanager.java:524) 07-21 14:53:26.875: error/androidruntime(8645): @ prototype.smsonport.smsonportactivity.sendsms(smsonportactivity.java:139) 07-21 14:53:26.875: error/androidruntime(8645): @ prototype.smsonport.smsonportactivity.onclick(smsonportactivity.java:38) 07-21 14:53:26.875: error/androidruntime(8645): @ android.view.view.performclick(view.java:2408) 07-21 14:53:26.875: error/androidruntime(8645): @ android.view.view$performclick.run(view.java:8817) 07-21 14:53:26.875: error/androidruntime(8645): @ android.os.handler.handlecallback(handler.java:587) 07-21 14:53:26.875: error/androidruntime(8645): @ android.os.handler.dispatchmessage(handler.java:92) 07-21 14:53:26.875: error/androidruntime(8645): @ android.os.looper.loop(looper.java:144) 07-21 14:53:26.875: error/androidruntime(8645): @ android.app.activitythread.main(activitythread.java:4937) 07-21 14:53:26.875: error/androidruntime(8645): @ java.lang.reflect.method.invokenative(native method) 07-21 14:53:26.875: error/androidruntime(8645): @ java.lang.reflect.method.invoke(method.java:521) 07-21 14:53:26.875: error/androidruntime(8645): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 07-21 14:53:26.875: error/androidruntime(8645): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 07-21 14:53:26.875: error/androidruntime(8645): @ dalvik.system.nativestart.main(native method)
here function
string sent = "sms_sent"; string delivered = "sms_delivered"; pendingintent sendpi = pendingintent.getbroadcast(getapplicationcontext(), 0, new intent(sent), 0); pendingintent deliveredpi = pendingintent.getbroadcast(getapplicationcontext(), 0, new intent( delivered), 0); smsmanager sms = smsmanager.getdefault(); short s = short.parseshort(portstr); short port = s; log.d("data", "sending sms :: "+phonenumber); log.d("data", "sending sms message :: "+msgstr); log.d("data", "sending sms on port :: "+port); sms.senddatamessage(phonenumber, null, port, msgstr.getbytes(), sendpi, deliveredpi);
all phonenumber, msgstr, port comes edittext fields of xml layout file. missing on here? appreciated.
send.setonclicklistener(new onclicklistener() { public void onclick(view v) { // todo auto-generated method stub string phoneno = "phone number"; string message = "content of msg"; if (phoneno.length() > 0 && message.length() > 0) { telephonymanager telmgr = (telephonymanager) getsystemservice(context.telephony_service); int simstate = telmgr.getsimstate(); switch (simstate) { case telephonymanager.sim_state_absent: displayalert(); break; case telephonymanager.sim_state_network_locked: // break; case telephonymanager.sim_state_pin_required: // break; case telephonymanager.sim_state_puk_required: // break; case telephonymanager.sim_state_ready: // sendsms(phoneno, message); break; case telephonymanager.sim_state_unknown: // break; } } else { toast.maketext(getbasecontext(), "please enter both phone number , message.", toast.length_short).show(); } } private void sendsms(string phonenumber, string message) { string sent = "sms_sent"; string delivered = "sms_delivered"; pendingintent sentpi = pendingintent.getbroadcast(youractivity.this, 0, new intent(sent), 0); pendingintent deliveredpi = pendingintent.getbroadcast(youractivity.this, 0, new intent(delivered), 0); // ---when sms has been sent--- registerreceiver(new broadcastreceiver() { @override public void onreceive(context arg0, intent arg1) { switch (getresultcode()) { case activity.result_ok: toast.maketext(youractivity.this, "sms sent", toast.length_short).show(); break; case smsmanager.result_error_generic_failure: toast.maketext(youractivity.this, "generic failure", toast.length_short).show(); break; case smsmanager.result_error_no_service: toast.maketext(youractivity.this, "no service", toast.length_short).show(); break; case smsmanager.result_error_null_pdu: toast.maketext(youractivity.this, "null pdu", toast.length_short).show(); break; case smsmanager.result_error_radio_off: toast.maketext(getbasecontext(), "radio off", toast.length_short).show(); break; } } }, new intentfilter(sent)); // ---when sms has been delivered--- registerreceiver(new broadcastreceiver() { @override public void onreceive(context arg0, intent arg1) { switch (getresultcode()) { case activity.result_ok: toast.maketext(youractivity.this, "sms delivered", toast.length_short).show(); break; case activity.result_canceled: toast.maketext(youractivity.this, "sms not delivered", toast.length_short).show(); break; } } }, new intentfilter(delivered)); smsmanager sms = smsmanager.getdefault(); sms.sendtextmessage(phonenumber, null, message, sentpi, deliveredpi); intent smsintent = new intent(youractivity.this, secondactivity.activity); startactivity(smsintent); }
Comments
Post a Comment