Hi,
I have just started developing apps in android and am having problem
with my application, where i am taking text from a textview into a
string and then sending it as SMS.

It worked only twice but later on, i am getting null pointer
exception.. pls check my code below..:

Message sending Method:

public void sendMessage(String phoneNumber, String msg) {

                Log.d("Sending message","Message="+msg);
                String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";

                //for(int i=0;i<phno.size();i++){
                        //String phoneNumber=phno.get(i).toString();

                        PendingIntent sentPI = 
PendingIntent.getBroadcast(context, 0, new
Intent(SENT), 0);

                        PendingIntent deliveredPI =
PendingIntent.getBroadcast(context, 0, new Intent(DELIVERED), 0);

                        //---when the SMS has been sent---
                        context.registerReceiver(new BroadcastReceiver(){
                            @Override
                            public void onReceive(Context arg0, Intent arg1) {
                                switch (getResultCode())
                                {
                                    case Activity.RESULT_OK:
                                        Toast.makeText(context,"SMS Sent",
Toast.LENGTH_SHORT).show();
                                        break;

                                    case 
SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                                         Toast.makeText(context,"Generic 
failure",
Toast.LENGTH_LONG).show();
                                         break;
                                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                                        Toast.makeText(context,"No service",
Toast.LENGTH_LONG).show();
                                        break;
                                    case SmsManager.RESULT_ERROR_NULL_PDU:
                                        Toast.makeText(context,"Null PDU",
Toast.LENGTH_LONG).show();
                                        break;
                                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                                        Toast.makeText(context,"Radio off",
Toast.LENGTH_LONG).show();
                                        break;
                                }
                            }
                        }, new IntentFilter(SENT));

                        //---when the SMS has been delivered---
                        context.registerReceiver(new BroadcastReceiver(){
                            @Override
                            public void onReceive(Context arg0, Intent arg1) {
                                switch (getResultCode())
                                {
                                    case Activity.RESULT_OK:
                                            Toast.makeText(context,"SMS 
delivered",
Toast.LENGTH_LONG).show();
                                            break;
                                    case Activity.RESULT_CANCELED:
                                        Toast.makeText(context,"SMS not 
delivered",
Toast.LENGTH_LONG).show();
                                        break;
                                }
                            }

                        }, new IntentFilter(DELIVERED));

                        SmsManager sms = SmsManager.getDefault();
                        sms.sendTextMessage(phoneNumber, " ", msg, sentPI,
deliveredPI);
                }

Method Invocation:

sendMessage("5556", sms);

I am just using it between 2 emulators.
I need your help..

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to