开发者

Sending an SMS in an Android application

开发者 https://www.devze.com 2023-03-25 13:53 出处:网络
I made a send application. How can I check message sending without an actual device? sendSms.setOnClickListener(new View.OnClickListener()

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);
    }
});


  1. Open two emulators.
  2. Run your program in one emulator.
  3. In the line "sms.sendTextMessage(phoneNumber, null, template, pi, null);" substitute phoneNumber with the emulator number. For example, 5554/5556, etc.
  4. On successful running of your code the other emulator will receive an SMS.
0

精彩评论

暂无评论...
验证码 换一张
取 消