Create Intent to share Text - Android Intent

Android examples for Intent:Open App

Description

Create Intent to share Text

Demo Code


//package com.java2s;

import android.app.Activity;

import android.content.Intent;

import android.widget.Toast;

public class Main {
    public static void shareText(Activity activity, String subject,
            String text, int chooserTitleID) {
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
        i.putExtra(Intent.EXTRA_EMAIL, "");
        i.putExtra(Intent.EXTRA_SUBJECT, subject);
        i.putExtra(Intent.EXTRA_TEXT, text);
        try {// www. j  a v  a 2  s.  c o m
            activity.startActivity(Intent.createChooser(i,
                    activity.getString(chooserTitleID)));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(activity, "Unable to find app",
                    Toast.LENGTH_SHORT).show();
        }

    }
}

Related Tutorials