一键发圈,一键转发到微信朋友圈或者微信好友

2023-10-15 04:58

本文主要是介绍一键发圈,一键转发到微信朋友圈或者微信好友,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

转载地址:http://blog.csdn.net/zflove168/article/details/79216773


package com.derivative.client.util;import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;import com.derivative.client.R;import java.io.File;
import java.util.ArrayList;/*** 拉起微信,朋友圈功能类,支持单张图片,多张图片,文字*/
public class ShareUtils {PopupWindow popupWindow;Context context;private String path;//单张图片路径private String content;private Button btn;private Uri[] uris;//多张图片路径uri数组public ShareUtils(Context context, String content){this.context=context;//  this.path=path;this.content=content;//  this.btn=btn;showpop();}public void setUri(Uri[] uris){this.uris = uris;}public void setPath(String path){this.path = path;}private void showpop() {View view= LayoutInflater.from(context).inflate(R.layout.share_view, null);ImageView img_weixin= (ImageView) view.findViewById(R.id.share_weixin);ImageView img_pyq= (ImageView) view.findViewById(R.id.share_pengyouquan);popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT, true);popupWindow.setBackgroundDrawable(new BitmapDrawable()); // 点击返回按钮popwindow消失img_weixin.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if (StringUtils.isWeixinAvilible(context)) {// 判断是否安装微信客户端// shareweixin(path);shareWXSomeImg(context,uris);// login(SHARE_MEDIA.WEIXIN);} else {ActivityUtil.showToast(context, "请安装微信客户端");}popupWindow.dismiss();}});img_pyq.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if (StringUtils.isWeixinAvilible(context)) {// 判断是否安装微信客户端//   shareweipyq(path,content);//拉起微信朋友圈带一张图片shareweipyqSomeImg(context,uris);//拉起微信朋友圈带多张图片// login(SHARE_MEDIA.WEIXIN);} else {ActivityUtil.showToast(context, "请安装微信客户端");}popupWindow.dismiss();}});popupWindow.showAtLocation( LayoutInflater.from(context).inflate(R.layout.activity_posterxq, null).findViewById(R.id.img_share), Gravity.BOTTOM, 0, 0);// 先设置popwindow的所有参数,最后再show}/*** 拉起微信好友发送单张图片* */private void shareweixin(String path){Uri uriToImage = Uri.fromFile(new File(path));Intent shareIntent = new Intent();//发送图片到朋友圈//ComponentName comp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI");//发送图片给好友。ComponentName comp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");shareIntent.setComponent(comp);shareIntent.setAction(Intent.ACTION_SEND);shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);shareIntent.setType("image/jpeg");context.startActivity(Intent.createChooser(shareIntent, "分享图片"));}/*** 拉起微信朋友圈发送单张图片* */private void shareweipyq(String path,String content){Uri uriToImage = Uri.fromFile(new File(path));Intent shareIntent = new Intent();//发送图片到朋友圈ComponentName comp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI");//发送图片给好友。
//        ComponentName comp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");shareIntent.setComponent(comp);shareIntent.putExtra("Kdescription", content);shareIntent.setAction(Intent.ACTION_SEND);shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);shareIntent.setType("image/jpeg");context.startActivity(Intent.createChooser(shareIntent, "分享图片"));}/*** 拉起微信朋友圈发送多张图片* */private void shareweipyqSomeImg(Context context,Uri[] uri){Intent shareIntent = new Intent();//1调用系统分析shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//2添加图片数组ArrayList<Uri> imageUris = new ArrayList<>();for (int i = 0; i < uri.length; i++) {imageUris.add(uri[i]);}shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,imageUris);shareIntent.setType("image/*");//3指定选择微信ComponentName componentName = new ComponentName("com.tencent.mm","com.tencent.mm.ui.tools.ShareToTimeLineUI");shareIntent.setComponent(componentName);//4开始分享context.startActivity(Intent.createChooser(shareIntent,"分享图片"));}/*** 拉起微信发送多张图片给好友* */private void shareWXSomeImg(Context context,Uri[] uri){Intent shareIntent = new Intent();//1调用系统分析shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//2添加图片数组ArrayList<Uri> imageUris = new ArrayList<>();for (int i = 0; i < uri.length; i++) {imageUris.add(uri[i]);}shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,imageUris);shareIntent.setType("image/*");//3指定选择微信ComponentName componentName = new ComponentName("com.tencent.mm","com.tencent.mm.ui.tools.ShareImgUI");shareIntent.setComponent(componentName);//4开始分享context.startActivity(Intent.createChooser(shareIntent,"分享图片"));}
}

这篇关于一键发圈,一键转发到微信朋友圈或者微信好友的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/215456

相关文章

Python基于微信OCR引擎实现高效图片文字识别

《Python基于微信OCR引擎实现高效图片文字识别》这篇文章主要为大家详细介绍了一款基于微信OCR引擎的图片文字识别桌面应用开发全过程,可以实现从图片拖拽识别到文字提取,感兴趣的小伙伴可以跟随小编一... 目录一、项目概述1.1 开发背景1.2 技术选型1.3 核心优势二、功能详解2.1 核心功能模块2.

Python实现一键PDF转Word(附完整代码及详细步骤)

《Python实现一键PDF转Word(附完整代码及详细步骤)》pdf2docx是一个基于Python的第三方库,专门用于将PDF文件转换为可编辑的Word文档,下面我们就来看看如何通过pdf2doc... 目录引言:为什么需要PDF转Word一、pdf2docx介绍1. pdf2docx 是什么2. by

如何基于Python开发一个微信自动化工具

《如何基于Python开发一个微信自动化工具》在当今数字化办公场景中,自动化工具已成为提升工作效率的利器,本文将深入剖析一个基于Python的微信自动化工具开发全过程,有需要的小伙伴可以了解下... 目录概述功能全景1. 核心功能模块2. 特色功能效果展示1. 主界面概览2. 定时任务配置3. 操作日志演示

Redis迷你版微信抢红包实战

《Redis迷你版微信抢红包实战》本文主要介绍了Redis迷你版微信抢红包实战... 目录1 思路分析1.1hCckRX 流程1.2 注意点①拆红包:二倍均值算法②发红包:list③抢红包&记录:hset2 代码实现2.1 拆红包splitRedPacket2.2 发红包sendRedPacket2.3 抢

SpringBoot后端实现小程序微信登录功能实现

《SpringBoot后端实现小程序微信登录功能实现》微信小程序登录是开发者通过微信提供的身份验证机制,获取用户唯一标识(openid)和会话密钥(session_key)的过程,这篇文章给大家介绍S... 目录SpringBoot实现微信小程序登录简介SpringBoot后端实现微信登录SpringBoo

PyQt5+Python-docx实现一键生成测试报告

《PyQt5+Python-docx实现一键生成测试报告》作为一名测试工程师,你是否经历过手动填写测试报告的痛苦,本文将用Python的PyQt5和python-docx库,打造一款测试报告一键生成工... 目录引言工具功能亮点工具设计思路1. 界面设计:PyQt5实现数据输入2. 文档生成:python-

Android实现一键录屏功能(附源码)

《Android实现一键录屏功能(附源码)》在Android5.0及以上版本,系统提供了MediaProjectionAPI,允许应用在用户授权下录制屏幕内容并输出到视频文件,所以本文将基于此实现一个... 目录一、项目介绍二、相关技术与原理三、系统权限与用户授权四、项目架构与流程五、环境配置与依赖六、完整

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

SpringBoot实现微信小程序支付功能

《SpringBoot实现微信小程序支付功能》小程序支付功能已成为众多应用的核心需求之一,本文主要介绍了SpringBoot实现微信小程序支付功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作... 目录一、引言二、准备工作(一)微信支付商户平台配置(二)Spring Boot项目搭建(三)配置文件

使用Python实现一键隐藏屏幕并锁定输入

《使用Python实现一键隐藏屏幕并锁定输入》本文主要介绍了使用Python编写一个一键隐藏屏幕并锁定输入的黑科技程序,能够在指定热键触发后立即遮挡屏幕,并禁止一切键盘鼠标输入,这样就再也不用担心自己... 目录1. 概述2. 功能亮点3.代码实现4.使用方法5. 展示效果6. 代码优化与拓展7. 总结1.