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));
    }

  • 相关阅读:
    最大子数组问题:股票
    dfs小练 【dfs】
    java小知识点简单回顾
    cdoj841-休生伤杜景死惊开 (逆序数变形)【线段树 树状数组】
    二路归并排序算法
    优秀Python学习资源收集汇总(强烈推荐)
    怎么学习逆向工程?
    __cdecl 、__fastcall、__stdcall
    getchar()、putchar()、gets()、puts()、cin.get()、cin.getline()、getline()
    <cctype>库
  • 原文地址:https://www.cnblogs.com/wgscd/p/6612479.html
Copyright © 2011-2022 走看看