zoukankan      html  css  js  c++  java
  • Android 一键分享功能简单实现


    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;

    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;

    public class ShareManager {

    //分享文件
    public static void shareFiles(Context context, List fileList) {
    if(context == null || fileList == null || fileList.size() < 1) {
    return;
    }
    ArrayList uriList = new ArrayList();
    for(File file : fileList) {
    Uri uri = Uri.fromFile(file);
    uriList.add(uri);
    }
    Intent intent = null;
    boolean isMultiple = uriList.size() > 1;
    if(isMultiple) {
    intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.setType("**");
    intent.putExtra(Intent.EXTRA_STREAM, uriList.get(0));
    }
    context.startActivity(Intent.createChooser(intent, "Choose a channel to share your files..."));
    }
    //分享图片
    public static void shareImage(Context context, File imageFile) {
    if(context == null || imageFile == null) {
    return;
    }
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/*");
    Uri uri = Uri.fromFile(imageFile);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    context.startActivity(Intent.createChooser(intent, "Choose a channel to share your image..."));
    }
    //分享文字
    public static void shareText(Context context, String text) {
    if(context == null || text == null) {
    return;
    }
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, text);
    context.startActivity(Intent.createChooser(intent, "Choose a channel to share your text..."));
    }
    }
    --------------------- 

  • 相关阅读:
    小白安装使用Redis
    Mysql的Sql语句优化
    maximo入门----用户使用提要
    时不时刷刷BOSS 看看技术需求
    2019.7.10整理
    docker使用入门
    docker之windows安装&centOS安装
    HashTable学习
    Hashmap学习
    红黑树学习
  • 原文地址:https://www.cnblogs.com/ly570/p/11299135.html
Copyright © 2011-2022 走看看