安卓分享 直接调用系统的分享

Android 调用系统分享文字、图片、文件,可直达微信、朋友圈、QQ、QQ空间、微博
兼容SDK 18以上的系统,直接调用系统分享功能,分享文本、图片、文件到第三方APP,如:微信、QQ、微博等
因为偷懒,可直达微信、朋友圈、QQ、QQ空间、微博的分享仅写了图片分享的,其他的文本、文件分享不常用到,就不写了。
具体图片分享区分单张图片分享和多张图片分享,详情请看代码:

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.StrictMode;
import android.text.TextUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**

  • 分享文件、图片、文本
  • Created by 她叫我小渝 on 2016/10/15.
    */

public class ShareFileUtils {

/**
 * 分享文本
 *
 * @param context
 * @param path
 */
public static void shareUrl(Context context, String path) {
    if (TextUtils.isEmpty(path)) {
        return;
    }

    checkFileUriExposure();

    Intent it = new Intent(Intent.ACTION_SEND);
    it.putExtra(Intent.EXTRA_TEXT, path);
    it.setType("text/plain");
    context.startActivity(Intent.createChooser(it, "分享APP"));
}

/**
 * 分享文件
 *
 * @param context
 * @param path
 */
public static void shareFile(Context context, String path) {
    if (TextUtils.isEmpty(path)) {
        return;
    }

    checkFileUriExposure();

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));  //传输图片或者文件 采用流的方式
    intent.setType("*/*");   //分享文件
    context.startActivity(Intent.createChooser(intent, "分享"));
}

/**
 * 分享单张图片
 *
 * @param context
 * @param path
 */
public static void shareImage(Context context, String path) {
    shareImage(context, path, null, null, null);
}

/**
 * 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值