zoukankan      html  css  js  c++  java
  • Android 使用系统自带分享功能

    way1:

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");// setType("audio/*");
        intent.putExtra(Intent.EXTRA_SUBJECT, "share");
        intent.putExtra(Intent.EXTRA_TEXT, "test http://www.qq.com/   测试");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(Intent.createChooser(intent, getTitle()));
    

    way2:

    bgimg0 = getImageFromAssetsFile("Cat_Blink/cat_blink0000.png");

    /**
    * 从Assets中读取图片
    */
    private Bitmap getImageFromAssetsFile(String fileName)
    {
    Bitmap image = null;
    AssetManager am = getResources().getAssets();
    try
    {
    InputStream is = am.open(fileName);
    image = BitmapFactory.decodeStream(is);
    is.close();
    }
    catch (IOException e)
    {
    e.printStackTrace();
    }

        return image;
    
    }
    

    上面的代码是从assets中获取图片的代码,下面的代码是分享图片的代码:

    /**
    * 分享功能
    *
    * @param context
    * 上下文
    * @param activityTitle
    * Activity的名字
    * @param msgTitle
    * 消息标题
    * @param msgText
    * 消息内容
    * @param imgPath
    * 图片路径,不分享图片则传null
    */
    public void shareMsg(String activityTitle, String msgTitle, String msgText,
    String imgPath) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    if (imgPath == null || imgPath.equals("")) {
    intent.setType("text/plain"); // 纯文本
    } else {
    File f = new File(imgPath);
    if (f != null && f.exists() && f.isFile()) {
    intent.setType("image/jpg");
    Uri u = Uri.fromFile(f);
    intent.putExtra(Intent.EXTRA_STREAM, u);
    }
    }
    intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);
    intent.putExtra(Intent.EXTRA_TEXT, msgText);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(Intent.createChooser(intent, activityTitle));
    }

  • 相关阅读:
    团队作业 总结
    个人作业 Alpha项目测试
    第二次作业
    交互式多媒体图书平台的设计与实现
    基于VS Code的C++语言的构建调试环境搭建指南
    码农的自我修养之必备技能 学习笔记
    工程化编程实战callback接口学习
    如何测评一个软件工程师的计算机网络知识水平和编程能力
    深入理解TCP协议及其源代码
    Socket与系统调用深度分析
  • 原文地址:https://www.cnblogs.com/wgscd/p/6612479.html
Copyright © 2011-2022 走看看