Reputation: 857
Assume,
i have sent a sms from emulator to my mobile number,but my mobile received nothing.Is it possible to view that sent sms on my mobile from "EMULATOR".If so how?
I have done this so far and its toasting as "SMS sent". Please find my source below
public class Send_sms extends Activity {
private static final String TAG = "Send_sms";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main12);
Button sndbtn =(Button)findViewById(R.id.but_send_ok);
sndbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
EditText addrTxt = (EditText)Send_sms.this.findViewById(R.id.editText_number);
EditText msgTxt = (EditText)Send_sms.this.findViewById(R.id.editText_write_msg);
try
{
sendSmsMessage(addrTxt.getText().toString(),msgTxt.getText().toString());
Toast.makeText(Send_sms.this,"Sms sent",Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(Send_sms.this,"Failed to send sms",Toast.LENGTH_LONG).show();
}
}});
}
@Override
protected void onDestroy() {
super.onDestroy();
}
private void sendSmsMessage(String address,String message)throws Exception
{
SmsManager smsMgr = SmsManager.getDefault();
smsMgr.sendTextMessage(address,null,message,null,null);
}
}
Upvotes: 1
Views: 1159
Reputation: 4258
No it is not possible to send sms for emulator to real device because Emulator has a virtual device and a virtual device not able to communicate with a real device but you are able to send sms from a virtual device to another virtual device.
Upvotes: 1
Reputation: 4291
Using PendingIntent
object you're able to receive notifications from the Android system whether SMS was sent successfully or it failed.
To do so the 4th and 5th parameter of sendTextMessage()
should be set. See details here: enter link description here
For a working example check this out: http://mobiforge.com/developing/story/sms-messaging-android
Upvotes: 0