Cheers! Problem got resolved.
There were no appropriate intantiation of the phone number field of the mSmsManager.sendTextMessage() method. Alas! how silly mistake i made which took some time to figure out. I believe i got mislead because of nesting of onClickListener() methods. He he…
I am reposting the correct code to let be helpful for others.
public class DialogActivity extends Activity
{
private Dialog mDialog;
String editTextEnterMobileNum;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.setTitle("Incoming Server Message")
.setMessage("text")
.setCancelable(false)
.setPositiveButton("eReceipt?", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
mDialog = new Dialog(DialogActivity.this);
mDialog.setContentView(R.layout.ereceipt_dialog);
mDialog.setTitle("User Input");
final EditText phoneNo = (EditText) mDialog.findViewById(R.id.eReceiptEditText);
mDialog.findViewById(R.id.eReceiptOkButton).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
dismissDialog();
String number = phoneNo.getText().toString();
try{
android.telephony.SmsManager mSmsManager = android.telephony.SmsManager.getDefault();
mSmsManager.sendTextMessage(number, null, SmsReceiver.msgContent, null, null);
Toast.makeText(getApplicationContext(), "Your SMS has sent successfully!", Toast.LENGTH_LONG).show();
}
catch(Exception e){
Toast.makeText(getApplicationContext(), "Your SMS sent has failed!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
mDialog.show();
}
})
.setNegativeButton("Exit", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
//finish();
}
public void dismissDialog() {
if (mDialog != null) {
mDialog.dismiss();
mDialog = null;
}
}
}
solved Why android.telephony.SmsManager is not able to send message from Dialog Activity?