- /**
- * 分享功能
- * @param context 上下文
- * @param activityTitle Activity的名字
- * @param msgTitle 消息标题
- * @param msgText 消息内容
- * @param imgPath 图片路径,不分享图片则传null
- */
- public static void shareMsg(Context context, String activityTitle, String msgTitle, String msgText,
- String imgPath) {
- Intent intent = new Intent(Intent.ACTION_SEND);
- if (imgPath == null || imgPath.equals("")) {
- intent.setType("text/plain"); // 纯文本
- } else {
- File f = new File(imgPath);
- if (f != null && 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));
- }
android_分享 图片 和 文字
最新推荐文章于 2024-05-10 16:31:50 发布