zoukankan      html  css  js  c++  java
  • Android 实现系统分享

    使用手机上的程序,来分享/发送,比如QQ的“发送到我的电脑”。

    1、分享/发送文本内容

    1  Intent shareIntent = new Intent();
    2         shareIntent.setAction(Intent.ACTION_SEND);
    3         shareIntent.setType("text/plain");
    4         //要分享的文本内容,选择某项后会直接把这段文本发送出去,相当于调用选中的应用的接口,并传参
    5         shareIntent.putExtra(Intent.EXTRA_TEXT, "Here is the Shared text.");
    6         //需要使用Intent.createChooser,这里我们直接复用。第二个参数并不会显示出来
    7         shareIntent = Intent.createChooser(shareIntent, "Here is the title of Select box");
    8         startActivity(shareIntent);

    通用步骤:

    首先将Intent的cation设置为Intent.ACTION_SEND,

    其次根据分享的内容设置不同的Type,

    然后根据不同的社交平台设置相关Extras,

    最后创建并启动选择器

    2、分享/发送单张图片

    1  //指定要分享的图片路径
    2         Uri imgUri = Uri.parse("mnt/sdcard/1.jpg");
    3         Intent shareIntent = new Intent();
    4         shareIntent.setAction(Intent.ACTION_SEND);
    5         shareIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
    6         shareIntent.setType("image/*");
    7         shareIntent = Intent.createChooser(shareIntent, "Here is the title of Select box");
    8         startActivity(shareIntent);

    注意根目录为     mnt/sdcard/   

    3、分享/发送多张图片

     1  Uri imgUri1 = Uri.parse("mnt/sdcard/1.jpg");
     2         Uri imgUri2 = Uri.parse("mnt/sdcard/2.jpg");
     3         ArrayList<Uri> imgUris = new ArrayList<Uri>();   //使用集合保存
     4         imgUris.add(imgUri1); 
     5         imgUris.add(imgUri2); 
     6 
     7         Intent shareIntent = new Intent();
     8         shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);    //注意是Intent_ACTION_MULTIPLE
     9         shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imgUris);   //注意是方法是putParcelableArrayListExtra()
    10         shareIntent.setType("image/*");
    11         shareIntent = Intent.createChooser(shareIntent, "Here is the title of Select box");
    12         startActivity(shareIntent);
  • 相关阅读:
    几个有趣的在线设计网站搜集
    动物水池png+ico图标:pool
    看看3150亿美元叠起来有多高
    卡巴斯基免费key发布网站:kaspersky
    58个精品壁纸分享网站[精品]
    一套华丽的vista安装包png+ico图标:vistalike
    32个精品国外图文结合photoshop效果教程
    超酷背景笔刷[abr格式]:grunge
    针对MM的在线处理图片网站:Taaz
    如何设计web2.0的图标[两个photoshop web2.0样式asl下载]
  • 原文地址:https://www.cnblogs.com/chy18883701161/p/10887093.html
Copyright © 2011-2022 走看看