Hi
Sir , I am new on Android platform and I have written a separate class for Sending SMS with confirmation code but when I send SMS through this then I face a problem that Your application has closed unexpectedly due to Null Pointer exception Actually I have send the sms from SettingScreen Activity through send_SMS method defined here sir pl help me I bind that code with the query in this regards
thanks
Om Parkash Kaushik
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.app.PendingIntent;
import android.telephony.SmsManager;
import android.widget.Toast;
import android.app.Activity;
public class SendSMS extends Activity {
private Context ctx;
public SendSMS(Context object){
this.ctx = object;
}
public void send_SMS(String phoneNumber, String message)
{
try{
String SENT = "SMS_SENT";
PendingIntent sentPI = PendingIntent.getBroadcast(ctx.getApplicationContext(), 0, new Intent(SENT),0);
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS_SNT",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "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));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, null);
}catch(Exception e){
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}