Use Intent to send SMS message

Description

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  a va  2  s . c o  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;
    }

}
Use Intent to send SMS message




















Home »
  Android »
    Android Basics »




Hello Android
Resources
Activity
Calendar
Camera
Contact
Content Provider
Database
Hardware
Intent
Location
Media
Network
Notification
Preference
Sensor
Service
SMS