package com.lean56.andplug.utils; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.text.TextUtils; import java.io.File; /** * ShareUtils * offers system share intent call * * @author Charles */ public class ShareUtils { public static void shareMsg(Context context, String activityTitle, String msgTitle, String msgText, String imgPath) { Intent intent = new Intent(Intent.ACTION_SEND); if (TextUtils.isEmpty(imgPath)) { intent.setType("text/plain"); // 纯文本 } else { File f = new File(imgPath); if (f.exists() && f.isFile()) { intent.setType("image/png"); Uri u = Uri.fromFile(f); intent.putExtra(Intent.EXTRA_STREAM, u); } } intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle); intent.putExtra(Intent.EXTRA_TEXT, msgText); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(Intent.createChooser(intent, activityTitle)); } }