share Text via Intent by mimetype - Android android.webkit

Android examples for android.webkit:MimeTypeMap

Description

share Text via Intent by mimetype

Demo Code

import android.content.Context;
import android.content.Intent;

public class Main {

  public static void shareText(Context context, String title, String subject, String text, String mime) {
    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.setType(mime);/*  w  w  w . j  av  a 2  s .c  o  m*/
    share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);

    // Add data to the intent, the receiving app will decide
    // what to do with it.
    share.putExtra(Intent.EXTRA_SUBJECT, subject);
    share.putExtra(Intent.EXTRA_TEXT, text);

    context.startActivity(Intent.createChooser(share, title));
  }

}

Related Tutorials