start Sms Intent - Android Intent

Android examples for Intent:SMS Send

Description

start Sms Intent

Demo Code


import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class Main{
    private static final String TAG = IntentHelper.class.getSimpleName();
    public static void startSmsIntent(Context context, String phoneNumber) {
        try {/*from   w  w  w.j av  a2 s . c o m*/
            Uri uri = Uri.parse("sms:" + phoneNumber);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.putExtra("address", phoneNumber);
            intent.setType("vnd.android-dir/mms-sms");
            context.startActivity(intent);
        } catch (Exception ex) {
            Log.e(TAG, "Error starting sms intent.", ex);
            Toast.makeText(context,
                    "Sorry, we couldn't find any app to send an SMS!",
                    Toast.LENGTH_SHORT).show();
        }
    }
}

Related Tutorials