Sends an SMS message to another device : SMS « Network « Android






Sends an SMS message to another device

 
package app.test;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Test extends Activity {
  Button btnSendEmail;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btnSendEmail = (Button) findViewById(R.id.btnSendEmail);        
        btnSendEmail.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) 
            {     
              String[] to = {"w@l.net", "w@g.com"};   
                String[] cc = {"c@l.net"};           
              sendEmail(to, cc, "Hello", "Hello my friends!");
            }
        });
    }
    
    //---sends an SMS message to another device---
    private void sendEmail(String[] emailAddresses, String[] carbonCopies, 
    String subject, String message)
    {     
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setData(Uri.parse("mailto:")); 
        String[] to = emailAddresses;   
        String[] cc = carbonCopies; 
        emailIntent.putExtra(Intent.EXTRA_EMAIL, to);   
        emailIntent.putExtra(Intent.EXTRA_CC, cc);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        emailIntent.putExtra(Intent.EXTRA_TEXT, message);        
        emailIntent.setType("message/rfc822");   
        startActivity(Intent.createChooser(emailIntent, "Email"));
    }
}

//main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<Button 
    android:id="@+id/btnSendEmail"  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:text="Send Email" />    

</LinearLayout>

   
  








Related examples in the same category

1.SMS Intent
2.extends BroadcastReceiver to create SMS Receiver
3.SMS Inbox Demo
4.SmsMessage Demo
5.Sms Messaging Demo
6.start SMS Intent