探索Android调用系统的分享功能
package com.xiaolijuan.sharedome; import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.RelativeLayout; import java.io.File;
import java.util.ArrayList; /**
* 项目名称:ShareDome
* 类描写叙述:
* 创建人:xiaolijuan
* 创建时间:2016/1/13 23:48
*/
public class ShareActivity extends Activity implements View.OnClickListener {
private RelativeLayout mRlShareText, mRlShareSingleimage, mRlShareMultipleimage, mRlShareQQ, mRlShareTencent, mRlShareWechat, mRlShareMicroblog, mRlShareOther; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share);
bindView();
} private void bindView() {
mRlShareText = (RelativeLayout) findViewById(R.id.rl_share_text);
mRlShareSingleimage = (RelativeLayout) findViewById(R.id.rl_share_singleimage);
mRlShareMultipleimage = (RelativeLayout) findViewById(R.id.rl_share_multipleimage); mRlShareQQ = (RelativeLayout) findViewById(R.id.rl_share_qq);
mRlShareTencent = (RelativeLayout) findViewById(R.id.rl_share_qqtencent);
mRlShareWechat = (RelativeLayout) findViewById(R.id.rl_share_wechat);
mRlShareMicroblog = (RelativeLayout) findViewById(R.id.rl_share_microblog);
mRlShareOther = (RelativeLayout) findViewById(R.id.rl_share_other); mRlShareText.setOnClickListener(new ShareText());
mRlShareSingleimage.setOnClickListener(new ShareSingleImage());
mRlShareMultipleimage.setOnClickListener(new ShareMultipleImage());
mRlShareQQ.setOnClickListener(this);
mRlShareTencent.setOnClickListener(this);
mRlShareWechat.setOnClickListener(this);
mRlShareMicroblog.setOnClickListener(this);
mRlShareOther.setOnClickListener(this);
} //分享文字至全部第三方软件
public class ShareText implements View.OnClickListener {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "这里是分享内容");
intent.setType("text/plain");
//设置分享列表的标题。而且每次都显示分享列表
startActivity(Intent.createChooser(intent, "分享到"));
}
} //分享单张图片至全部第三方软件
public class ShareSingleImage implements View.OnClickListener {
@Override
public void onClick(View v) {
String imagePath = Environment.getExternalStorageDirectory() + File.separator + "13e277bb0b9c2e3ab90229463357bf40.jpg";
//由文件得到uri
Uri imageUri = Uri.fromFile(new File(imagePath)); Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "分享到"));
}
} //分享多张图片至全部第三方软件
public class ShareMultipleImage implements View.OnClickListener {
@Override
public void onClick(View v) {
ArrayList<Uri> uriList = new ArrayList<>(); String path = Environment.getExternalStorageDirectory() + File.separator;
uriList.add(Uri.fromFile(new File(path+"13e277bb0b9c2e3ab90229463357bf40.jpg")));
uriList.add(Uri.fromFile(new File(path+"869895e73ddd710e8a132afb37461bf0.jpg")));
uriList.add(Uri.fromFile(new File(path+"4753fc4cd47aa1833c70df4c08f4b7fa.jpg")));
uriList.add(Uri.fromFile(new File(path+"355ee87cf0ff612331a790f31b3ad113.jpg")));
uriList.add(Uri.fromFile(new File(path+"ce61ad4d44e3099d87040f38faabbf56.jpg"))); Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "分享到"));
}
} @Override
public void onClick(View v) {
String pakName = "";
Intent intent = new Intent(Intent.ACTION_SEND); // 启动分享发送的属性
intent.setType("text/plain"); // 分享发送的数据类型
switch (v.getId()) {
case R.id.rl_share_qq:
pakName = "com.qzone"; //qq空间
break;
case R.id.rl_share_qqtencent:
pakName = "com.tencent.WBlog"; //腾讯微博
break;
case R.id.rl_share_wechat:
pakName = "com.tencent.mm"; //微信
break;
case R.id.rl_share_microblog:
pakName = "com.sina.weibo"; //微博
break;
case R.id.rl_share_other:
break;
default:
break;
}
intent.setPackage(pakName);
intent.putExtra(Intent.EXTRA_TEXT, "这里是分享内容"); // 分享的内容
this.startActivity(Intent.createChooser(intent, ""));// 目标应用选择对话框的标题;
}
}
因为分享功能是使用隐式调用Activtiy实现的,则需在响应的Activity中声明intent-filter。在相应的activity的xml里加上
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
探索Android调用系统的分享功能的更多相关文章
- Android 调用系统的分享[完美实现同一时候分享图片和文字]
android 系统的分享功能 private void share(String content, Uri uri){ Intent shareIntent = new Intent(Intent. ...
- Android调用系统分享功能总结
Android分享-调用系统自带的分享功能 实现分享功能的几个办法 1.调用系统的分享功能 2.通过第三方SDK,如ShareSDK,友盟等 3.自行使用各自平台的SDK,比如QQ,微信,微博各自的S ...
- Android 调用系统分享文字、图片、文件,可直达微信、朋友圈、QQ、QQ空间、微博
原文:Android 调用系统分享文字.图片.文件,可直达微信.朋友圈.QQ.QQ空间.微博 兼容SDK 18以上的系统,直接调用系统分享功能,分享文本.图片.文件到第三方APP,如:微信.QQ.微博 ...
- Android调用系统相册和拍照的Demo
最近我在群里看到有好几个人在交流说现在网上的一些Android调用系统相册和拍照的demo都有bug,有问题,没有一个完整的.确实是,我记得一个月前,我一同学也遇到了这样的问题,在低版本的系统中没问题 ...
- Android调用系统相机、自己定义相机、处理大图片
Android调用系统相机和自己定义相机实例 本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,而且因为涉及到要把拍到的照片显示出来,该样例也会涉及到Android载入大图片时候的处 ...
- Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例 本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显示出来,该例子也会涉及到Android加载大图片时候的处理 ...
- Android调用系统相机和文件浏览器
//拍照功能,调用系统的相机功能 Intent intent2 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResul ...
- android - 调用系统分享功能分享图片
step1: 编写分享代码, 将Uri的生成方式改为由FileProvider提供的临时授权路径,并且在intent中添加flag 注意:在Android7.0之后,调用系统分享,传入URI的时候可能 ...
- Android调用系统拍照裁剪和选图功能
最近项目中用到修改用户头像的功能,基本上都是模板代码,现在简单记录一下. 调用系统拍照 private fun openCamera() { //调用相机拍照 // 创建File对象,用于存储拍照后的 ...
随机推荐
- Node.js:Strea
ylbtech-Node.js:Stream 1.返回顶部 1. Node.js Stream(流) Stream 是一个抽象接口,Node 中有很多对象实现了这个接口.例如,对http 服务器发起请 ...
- html5之文件操作
用来把文件读入内存,并且读取文件中的数据.FileReader接口提供了一个异步API,使用该API可以在浏览器主线程中异步访问文件系统,读取文件中的数据.到目前文职,只有FF3.6+和Chrome6 ...
- 计算机网络自顶向下方法第2章-应用层(application-layer).2
2.4 DNS:因特网的目录服务 2.4.1 DNS提供的服务 DNS的定义 实体层面看,DNS是一个由分层的DNS服务器实现的分布式数据库 协议层面看,DNS是一个使得主机能够查询分布式数据库的应用 ...
- LeetCode.2-两个数字相加(Add Two Numbers)
这是悦乐书的第340次更新,第364篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Medium级别的第1题(顺位题号是2).给定两个非空链表,表示两个非负整数. 数字以相反的顺序存储, ...
- TensorFlow-正弦函数拟合
MNIST的代码还是有点复杂,一大半内容全在搞数据,看了半天全是一滩烂泥.最关键的是最后输出就是一个accuracy,我根本就不关心你准确率是0.98还是0.99好吗?我就想看到我手写一个5,你程序给 ...
- Windows Phone - 按钮/button 控件
System.Windows.Controls.Button button控件一.button控件的各种样式的展示可以通过 …… 来给控件定义公共的样式调用样式的方法:在Button控件上添加样式 ...
- CBIR--Survey.C/GPU优化.Sys搭建
一:CBIR综述:转自于wiki:http://zh.wikipedia.org/wiki/CBIR 参考链接:http://blog.csdn.net/kezunhai/article/detail ...
- java中4种修饰符访问权限的区别及详解全过程
java中4种修饰符访问权限的区别及详解全过程 http://jingyan.baidu.com/article/fedf0737700b3335ac8977ca.html java中4中修饰符分别为 ...
- preparedStatement平台:
public class cs{ public static void main(String[] args){ try{ class.forName("com.mysql.jdbc.Dri ...
- mysql 各项操作流程
启动mysql:进入命令行输入:net start mysql 如果失败则显示:服务名无效,需跳转到指定Bin目录下进行启动mysql, 成功则进行下一步:登陆 :mysql -uroot -proo ...