Back to project page CommonLibs.
The source code is released under:
Apache License
If you think the Android project CommonLibs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.alex.common.utils; /* www .j av a 2s .com*/ import java.io.File; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.text.TextUtils; /** * ????? * @author caisenchuan */ public class ShareUtils { /*-------------------------- * ??? *-------------------------*/ /*-------------------------- * ????????? *-------------------------*/ /*-------------------------- * ?? *-------------------------*/ /*-------------------------- * public?? *-------------------------*/ /** * ???? * @param context * @param msgTitle * @param msgText * @param imgPath */ public static void share(Context context, 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 != null && f.exists() && f.isFile()) { intent.setType("image/*"); Uri u = Uri.fromFile(f); intent.putExtra(Intent.EXTRA_STREAM, u); } } String activityTitle = "Share"; 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)); } /*-------------------------- * protected?? *-------------------------*/ /*-------------------------- * private?? *-------------------------*/ }