当前位置: 移动技术网 > IT编程>移动开发>Android > Android编程实现调用系统分享功能示例

Android编程实现调用系统分享功能示例

2019年07月24日  | 移动技术网IT编程  | 我要评论

kkamooong,近期电影上映,焦作旅游网

本文实例讲述了android编程实现调用系统分享功能。分享给大家供大家参考,具体如下:

/**
 * 调用系统的分享功能
 * created by admin on 15-4-13.
 */
public class shareactivity extends activity {
  @override
  protected void oncreate(bundle savedinstancestate) {
    super.oncreate(savedinstancestate);
    setcontentview(r.layout.share_layout);
  }
  //分享文字
  public void sharetext(view view) {
    intent shareintent = new intent();
    shareintent.setaction(intent.action_send);
    shareintent.putextra(intent.extra_text, "this is my share text.");
    shareintent.settype("text/plain");
    //设置分享列表的标题,并且每次都显示分享列表
    startactivity(intent.createchooser(shareintent, "分享到"));
  }
  //分享单张图片
  public void sharesingleimage(view view) {
    string imagepath = environment.getexternalstoragedirectory() + file.separator + "test.jpg";
    //由文件得到uri
    uri imageuri = uri.fromfile(new file(imagepath));
    log.d("share", "uri:" + imageuri); //输出:file:///storage/emulated/0/test.jpg
    intent shareintent = new intent();
    shareintent.setaction(intent.action_send);
    shareintent.putextra(intent.extra_stream, imageuri);
    shareintent.settype("image/*");
    startactivity(intent.createchooser(shareintent, "分享到"));
  }
  //分享多张图片
  public void sharemultipleimage(view view) {
    arraylist<uri> urilist = new arraylist<>();
    string path = environment.getexternalstoragedirectory() + file.separator;
    urilist.add(uri.fromfile(new file(path+"australia_1.jpg")));
    urilist.add(uri.fromfile(new file(path+"australia_2.jpg")));
    urilist.add(uri.fromfile(new file(path+"australia_3.jpg")));
    intent shareintent = new intent();
    shareintent.setaction(intent.action_send_multiple);
    shareintent.putparcelablearraylistextra(intent.extra_stream, urilist);
    shareintent.settype("image/*");
    startactivity(intent.createchooser(shareintent, "分享到"));
  }
}

页面效果:

 

更多关于android相关内容感兴趣的读者可查看本站专题:《android编程之activity操作技巧总结》、《android视图view技巧总结》、《android开发动画技巧汇总》、《android布局layout技巧总结》、《android开发入门与进阶教程》、《android资源操作技巧汇总》及《android控件用法总结

希望本文所述对大家android程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网