侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Android实现截图分享qq 微信功能

2023-06-03 星期六 / 0 评论 / 0 点赞 / 148 阅读 / 4043 字

在上篇文章给大家介绍了Android实现截图和分享功能的代码。感兴趣可以点击阅读,今天通过本文给大家介绍Android实现截图分享qq 微信功能。一起看看吧。前言现在很多应用都有截图分享的功能,今天就来讲讲截图分享吧今天

在上篇文章给大家介绍了Android实现截图和分享功能的代码。感兴趣可以点击阅读,今天通过本文给大家介绍Android实现截图分享qq 微信功能。一起看看吧。

前言

现在很多应用都有截图分享的功能,今天就来讲讲截图分享吧

今天涉及到以下内容:

  • Android截屏
  • Android分享
  • 效果图展示

ok,下面就来具体讲讲

一.权限,注意权限

先在自己的mainfast中添加以下权限:

.
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
.

然后是要申请Android7.0以上的权限,之前讲过了,这里就不再废话了。

二.截图分享类

代码如下:

.
package com.dialogfragmentdemo.util;import android.content.Context;import android.content.Intent;import android.graphics.Bitmap;import android.net.Uri;import java.io.File;import java.io.FileOutputStream;/** * Title:截屏分享 * Description: * 需要用户读写权限 * <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> * <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> * * Created by pei * Date: 2017/12/6 */public class ShotShareUtil { /**截屏分享,供外部调用**/ public static void shotShare(Context context){ //截屏 String path=screenShot(context); //分享 if(StringUtil.isNotEmpty(path)){  ShareImage(context,path); } } /**获取截屏**/ private static String screenShot(Context context){ String imagePath=null; Bitmap bitmap= ScreenUtil.snapShotWithoutStatusBar(context); if(bitmap!=null){  try {  // 图片文件路径  imagePath = SDCardUtil.getDiskCachePath()+"share.png";  LogUtil.e(ShotShareUtil.class, "====imagePath====" + imagePath);  File file = new File(imagePath);  FileOutputStream os = new FileOutputStream(file);  bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);  os.flush();  os.close();  return imagePath;  } catch (Exception e) {  LogUtil.e(ShotShareUtil.class, "====screenshot:error====" + e.getMessage());  } } return null; } /**分享**/ private static void ShareImage(Context context,String imagePath){ if (imagePath != null){  Intent intent = new Intent(Intent.ACTION_SEND); // 启动分享发送的属性  File file = new File(imagePath);  intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));// 分享的内容  intent.setType("image/*");// 分享发送的数据类型  Intent chooser = Intent.createChooser(intent, "Share screen shot");  if(intent.resolveActivity(context.getPackageManager()) != null){  context.startActivity(chooser);  } } else {  ToastUtil.shortShow("先截屏,再分享"); } }}
.

三.在mainactivity中调用

以下是示例代码:

.
@Override public void onClick(View v) { super.onClick(v); switch (v.getId()) {  case R.id.button:  LogUtil.e(MainActivity.class,"====我点击了====");  //截屏分享  ShotShareUtil.shotShare(mContext);  break;  default:  break; } }
.

四.效果图

上面是分享的时候,手机上没装qq和微信的情况,下面展示有qq,微信的情况

总结

以上所述是小编给大家介绍的Android实现截图分享qq 微信功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对..网站的支持!

广告 广告

评论区