Sending an SMS in an Android application
I made a send application. How can I check message sending without an actual device?
sendSms.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
//Toast.makeText(getApplicationContext(),template+"and"+phoneNumber,Toast.LENGTH_LONG).show();
if (phoneNumber.length()>0 && template.length()>0)
{
sendSMS(phoneNumber, template);
}
else
Toa开发者_StackOverflowst.makeText(getApplicationContext(), "please select name & template",Toast.LENGTH_SHORT).show();
}
private void sendSMS(String phoneNumber, String template)
{
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,new Intent(getApplicationContext(),Test2Activity.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, template, pi, null);
}
});
- Open two emulators.
- Run your program in one emulator.
- In the line "sms.sendTextMessage(phoneNumber, null, template, pi, null);" substitute phoneNumber with the emulator number. For example, 5554/5556, etc.
- On successful running of your code the other emulator will receive an SMS.
精彩评论