Android How to - Use Intent to send SMS message








The following code shows how to Use Intent to send SMS message.

Example

Main Activity Java code

import java.io.File;
import java.util.ArrayList;
//from ww w .j  av a 2 s  .  co  m
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Contacts;
import android.view.Menu;

public class MainActivity extends Activity {

    private Intent smsIntent;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        smsIntent = new Intent();
        smsIntent.setAction(Intent.ACTION_VIEW);
        smsIntent.setType("vnd.android-dir/mms-sms");
        smsIntent.putExtra("address", "8885551234");
        smsIntent.putExtra("sms_body", "SMS Body");
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add("SMS").setIntent(smsIntent);
        return true;
    }

}
null