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

Home
Android
1.2D Graphics
2.Animation
3.Core Class
4.Database
5.Date Type
6.Development
7.File
8.Game
9.Hardware
10.Media
11.Network
12.Security
13.UI
14.User Event
Android » Network » SMS 




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 = (ButtonfindViewById(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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.