share File via Intent - Android android.content

Android examples for android.content:Intent

Description

share File via Intent

Demo Code

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class Main {

  public static void shareFile(Context context, String title, String subject, String text, String mime, String path) {
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType(mime);/*www  .  ja va  2 s.co  m*/
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + path));
    sendIntent.putExtra(Intent.EXTRA_TEXT, text);
    context.startActivity(Intent.createChooser(sendIntent, title));
  }

}

Related Tutorials