直接上代码,工具类

import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.Toast;import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;public class WechatShareUtil {/*** 分享多图片到QQ*/public static void sharePicToQQNoSDK(Context context, List<String> paths) {if (isInstallQQ(context)) {Intent shareIntent = new Intent();shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);shareIntent.setType("image/*");// 遍历所有支持发送图片的应用。找到需要的应用ComponentName componentName = new ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");shareIntent.setComponent(componentName);ArrayList<Uri> imageList = new ArrayList<>();for (String picPath : paths) {Log.e("backinfo", picPath);File file = new File(picPath);if (file.exists()){Uri uri = null;if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {try {uri = Uri.parse(MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), file.getName(), null));} catch (FileNotFoundException e) {Toast.makeText(context,"图片不存在", Toast.LENGTH_SHORT).show();e.printStackTrace();}} else {uri = Uri.fromFile(file);}imageList.add(uri);}}if(imageList.size() == 0){Toast.makeText(context,"图片不存在", Toast.LENGTH_SHORT).show();return;}shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageList);context.startActivity(Intent.createChooser(shareIntent, "Share"));}}/*** 分享单图片到朋友圈* @param context* @param imagePath*/public static void sharePicsToWXFriendCircle(Context context, String imagePath) {if (!isInstallWeChart(context)) {Toast.makeText(context,"您没有安装微信", Toast.LENGTH_SHORT).show();return;}Intent intent = new Intent();intent.setComponent(new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI"));intent.setAction(Intent.ACTION_SEND);File f = new File(imagePath);Uri uri = null;if (f.exists()){if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {uri = getImageContentUri(context, f);} else {uri = Uri.fromFile(f);}}else {Toast.makeText(context,"图片不存在", Toast.LENGTH_SHORT).show();return;}intent.setType("image/*");intent.putExtra(Intent.EXTRA_STREAM, uri); //图片数据(支持本地图片的Uri形式)intent.putExtra("Kdescription", ""); //微信分享页面,图片上边的描述context.startActivity(intent);}/*** 唤醒微信* @param context*/public static void startWechat(Context context){Intent intent = new Intent(Intent.ACTION_MAIN);ComponentName cmp = new ComponentName("com.tencent.mm","com.tencent.mm.ui.LauncherUI");intent.addCategory(Intent.CATEGORY_LAUNCHER);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.setComponent(cmp);context.startActivity(intent);}/*** 分享图片给好友(多图片)* @param context* @param paths*/public static void sharePicToWechatNoSDK(Context context, List<String> paths) {if(!isInstallWeChart(context)){Toast.makeText(context,"您没有安装微信", Toast.LENGTH_SHORT).show();return;}Intent intent = new Intent();ComponentName comp = new ComponentName("com.tencent.mm","com.tencent.mm.ui.tools.ShareImgUI");intent.setComponent(comp);intent.setAction(Intent.ACTION_SEND_MULTIPLE);intent.setType("image/*");ArrayList<Uri> imageList = new ArrayList<>();for (String picPath : paths) {File file = new File(picPath);if (file.exists()){Uri uri = null;if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {try {uri = Uri.parse(MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), file.getName(), null));} catch (FileNotFoundException e) {Toast.makeText(context,"图片不存在", Toast.LENGTH_SHORT).show();e.printStackTrace();}} else {uri = Uri.fromFile(file);}imageList.add(uri);}}if(imageList.size() == 0){Toast.makeText(context,"图片不存在", Toast.LENGTH_SHORT).show();return;}intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageList); //图片数据(支持本地图片的Uri形式)context.startActivity(intent);}/*** 获取分享到微信朋友圈的uri格式* @param context* @param imageFile* @return*/public static Uri getImageContentUri(Context context, File imageFile) {String filePath = imageFile.getAbsolutePath();Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,new String[]{MediaStore.Images.Media._ID}, MediaStore.Images.Media.DATA +"=? ",new String[]{filePath}, null);Uri uri =null;if (cursor !=null) {if (cursor.moveToFirst()) {int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));Uri baseUri = Uri.parse("content://media/external/images/media");uri = Uri.withAppendedPath(baseUri, "" + id);}cursor.close();}if (uri ==null) {ContentValues values = new ContentValues();values.put(MediaStore.Images.Media.DATA, filePath);uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);}return uri;}/**检查是否安装微信* @param context* @return*/private static boolean isInstallWeChart(Context context){PackageInfo packageInfo = null;try {packageInfo = context.getPackageManager().getPackageInfo("com.tencent.mm", 0);} catch (Exception e) {packageInfo = null;e.printStackTrace();}if (packageInfo == null) {return false;} else {return true;}}/**检查是否安装QQ* @param context* @return*/private static boolean isInstallQQ(Context context){PackageInfo packageInfo = null;try {packageInfo = context.getPackageManager().getPackageInfo("com.tencent.mobileqq", 0);} catch (Exception e) {packageInfo = null;e.printStackTrace();}if (packageInfo == null) {return false;} else {return true;}}
}

FileDownloader 递归多文件下载

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.FileDownloadSampleListener;
import com.liulishuo.filedownloader.FileDownloader;
import com.weipai.dialog.LoadingDialog;
import com.weipai.main.contact.Contact;import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;public class DownloadFileUtil {private Context context;private String path;private boolean isShowLoading = true;private List<String> pathList;private List<String> netUrlList;private OnFilesDownloadListener listener;//private LoadingDialog dialog;public static DownloadFileUtil init(Context context, String path) {return new DownloadFileUtil(context, path);}private DownloadFileUtil(Context context, String path) {this.context = context;this.path = path;pathList = new ArrayList<>();netUrlList = new ArrayList<>();}public DownloadFileUtil setOnFilesDownloadListener(OnFilesDownloadListener listener){this.listener = listener;return this;}private int fileCount = 0;private OnSingleFileDownloadListener l = new OnSingleFileDownloadListener() {@Overridepublic void onCompleted(String path) {++fileCount;pathList.add(path);if (fileCount == netUrlList.size()){//dialog.dismiss();if (listener != null) listener.onCompleted(pathList);}else {downloadFile(netUrlList.get(fileCount), l);}}};/*** 递归下载多文件* @param urls*/public void downloadFiles(final List<String> urls){netUrlList.clear();netUrlList.addAll(urls);if (netUrlList.size() > 0) {//dialog = new LoadingDialog(context);//dialog.show();downloadFile(urls.get(0), l);}}/*** 单文件下载* @param url* @param listener*/public void downloadFile(String url, final OnSingleFileDownloadListener listener) {Log.e("backinfo", "downloadFile " + fileCount);Log.e("backinfo", "downloadFile url" + url);Log.e("backinfo", "downloadFile path" + path);String fileName = new Date().getTime() + ".jpg";/*if (fileName.isEmpty()) {if (fileCount == netUrlList.size() - 1) dialog.dismiss();return;}*/FileDownloader.getImpl().create(url).setPath(path + fileName, false).setCallbackProgressTimes(300).setMinIntervalUpdateSpeed(400).setAutoRetryTimes(3).setListener(new FileDownloadSampleListener() {@Overrideprotected void pending(BaseDownloadTask task, int soFarBytes, int totalBytes) {Log.e("backinfo", ",soFarBytes:" + soFarBytes + ",totalBytes:" + totalBytes + ",percent:" + soFarBytes * 1.0 / totalBytes + ",speed:" + task.getSpeed());}@Overrideprotected void progress(BaseDownloadTask task, int soFarBytes, int totalBytes) {Log.e("backinfo", ",soFarBytes:" + soFarBytes + ",totalBytes:" + totalBytes + ",percent:" + soFarBytes * 1.0 / totalBytes + ",speed:" + task.getSpeed());}@Overrideprotected void blockComplete(BaseDownloadTask task) {Log.e("backinfo", "blockComplete ");}@Overrideprotected void completed(BaseDownloadTask task) {//  VideoPlayerManager.instance().resumeVideoPlayer();File file = new File(task.getTargetFilePath());Log.e("backinfo",  "completed " + task.getTargetFilePath());if (file.exists()) {Uri localUri = Uri.fromFile(file);Intent localIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, localUri);context.sendBroadcast(localIntent);listener.onCompleted(file.getAbsolutePath());}}@Overrideprotected void paused(BaseDownloadTask task, int soFarBytes, int totalBytes) {Log.e("backinfo", "paused ");}@Overrideprotected void error(BaseDownloadTask task, Throwable e) {Log.e("backinfo", "error " + e.getLocalizedMessage());}@Overrideprotected void warn(BaseDownloadTask task) {Log.e("backinfo", "warn ");}}).start();}private interface OnSingleFileDownloadListener{void onCompleted(String path);}public interface OnFilesDownloadListener{void onCompleted(List<String> pathList);}/** 获取文件后缀 */public String getFileExtension(String url) {int i = url.lastIndexOf('.');if (i > 0 && i < url.length() - 1) {return url.substring(i + 1).toLowerCase();}return "";}
}

使用例:

DownloadFileUtil.init(context,  "/sdcard/DCIM/Camera/").setOnFilesDownloadListener(new DownloadFileUtil.OnFilesDownloadListener() {@Overridepublic void onCompleted(List<String> pathList) {WechatShareUtil.sharePicToQQNoSDK(context, pathList);}}).downloadFiles(urls);

Android——intent分享图片到微信好友、朋友圈、QQ相关推荐

  1. android中设置lmargin简书,超详细React Native实现微信好友/朋友圈分享功能-Android/iOS双平台通用...

    (一)前言 本文主要会涉及到以下内容: 微信开发者应用申请审核 安装配置微信分享库 微信好友/朋友圈功能实现 (二)应用申请审核 首先大家需要去微信开发平台去注册账号并且创建一个移动应用.(地址:ht ...

  2. 微信小程序分享图片给微信好友(如二维码)

    目录 前言 一.使用哪种api? 二.对图片的处理需要转化为临时路径 三.Windows端兼容性问题 前言 最近在公司开发一个微信小程序项目,用到的uniapp技术,在分享图片时,查看了uniapp的 ...

  3. 一键转发微信好友朋友圈,自动跟圈

    今天咱来讲一下如何实现一键转发朋友圈? 如何一键跟圈,多个微信快速同步发圈? 01 一键转发 浏览朋友圈,在此页面可以浏览所登录的微信号的好友朋友圈,可以实现快速点赞.评论.一键转发. 单击" ...

  4. java 朋友圈分享接口_微信发朋友圈api接口调用代码

    微信发朋友圈api接口调用代码,推送微信朋友圈.发朋友圈 /** * 触发推送朋友圈列表 * @author wechatno:tangjinjinwx * startTime传秒 * @blog h ...

  5. 微信小程序分享功能(微信好友,朋友圈)

    1.点击按钮实现分享微信好友 //html部分 <button class="share_list_button" open-type="share"&g ...

  6. 当你发现微信好友朋友圈是“一条杠”,你会把她、他删除吗?

    微信朋友出现'一条杠',大体有以下五种情况.如果不加以区分,无故删除对方,这显得有些不近人情.哪些情况可以删除对方,哪些情况不要删除对方?我从这五个方面分析这个问题. 1,微信好友不喜欢发朋友圈,这个 ...

  7. 微信小程序(uniapp)-实现分享图片给微信好友

    官方地址: 微信开放文档 | wx.showShareImageMenu(Object object) 示例代码: // 结构 <view @click="shareImg" ...

  8. 微信小程序分享图片给微信好友

    wx.showShareImageMenu(Object object) | 微信开放文档 <button class="share-item" bindtap=" ...

  9. Android工具类— 分享到QQ(QQ空间)、微信(朋友圈)

    1.分享到QQ.QQ空间: 首先第一步,在腾讯开发者平台注册,添加应用,获得APPID,然后下载SDK,导入到工程中:然后,在AndroidManifest中注册两个Activity,代码如下: &l ...

最新文章

  1. unity加载sprite_Unity 利用UGUI打包图集,动态加载sprite资源
  2. 使用Fiddler为满足某些特定格式的网络请求返回mock响应
  3. PHP vs Node.js vs Nginx-Lua(转)
  4. 利用Python绘制中国新型冠状病毒疫情图(国家和省)
  5. JSR303常见参数
  6. 首个视觉-语言预训练综述来了!
  7. 用NAnt 将StarTeam中的文件CheckOut回本地计算机
  8. 不用static,巧用对象.方法调用java中的函数
  9. 有些人真是笨的可以,劝我自己别多管闲事,切记切记
  10. modelsim安装_Vivado联合ModelSim
  11. html重置默认字体,html网页默认字体
  12. 网站换服务器 备案,网站换服务器备案吗
  13. 手把手教你用FineBI做数据可视化
  14. [-NDK 导引篇 -] 在NDK开发之前你应知道的东西
  15. 基于php+MySQL电脑外设商城网站毕业设计源码271538
  16. rk3288 android6,RK3288 的 Android 7.1.2 来了!
  17. 计算机网络--应用层(2)P2P应用
  18. (转)甲方乙方——赵民谈找工作
  19. Qt 视频上叠加透明图片
  20. 【跃迁之路】【631天】程序员高效学习方法论探索系列(实验阶段388-2018.11.04)...

热门文章

  1. sonarqube快速部署
  2. 2018年第23周-大数据的HDFS数据流及操作例子
  3. ASP.NET程序设计 ——琴社网站
  4. torch.rand (randn, random以及normal)对比
  5. Python正则表达式工具类文件的封装实例,提供了多个实例,并且在代码中包含中文注释
  6. UI之PS操作(一)操作(一)
  7. 在Excel中重复表格标题行
  8. iPhone设置163邮箱 收件服务器和发件服务器填写内容
  9. 风云再起 唯WiFi不败
  10. xps数据怎么导出为txt_XPS原始数据处理(含分峰拟合)