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, "分享到"));
    }
}

页面效果:

      

时间: 2024-08-26 20:14:35

Android:调用系统分享功能的相关文章

android - 调用系统分享功能分享图片

step1: 编写分享代码, 将Uri的生成方式改为由FileProvider提供的临时授权路径,并且在intent中添加flag 注意:在Android7.0之后,调用系统分享,传入URI的时候可能会导致程序闪退崩溃.这是由于7.0的新的文件权限导致的.下面的代码对其做了处理 public static int sharePic(Context context, String picFilePath) { File shareFile = new File(picFilePath); if (

Android调用系统分享功能以及createChooser的使用

工程结构 //效果图 点击测试分享                                                                                                          点击createChoose妙用       主要是看右边的,可不是用什么Dialog来搞的哦,而是你Activity程序,可以激活进去了 提示:这个东西可以延伸到一个音频文件,打开时,可以调用你的音乐播放器来播放哦,视频,图片,也是类似,可以调用你自己

Android 调用系统分享文字、图片、文件,可直达微信、朋友圈、QQ、QQ空间、微博

原文:Android 调用系统分享文字.图片.文件,可直达微信.朋友圈.QQ.QQ空间.微博 兼容SDK 18以上的系统,直接调用系统分享功能,分享文本.图片.文件到第三方APP,如:微信.QQ.微博等 因为偷懒,可直达微信.朋友圈.QQ.QQ空间.微博的分享仅写了图片分享的,其他的文本.文件分享不常用到,就不写了. 具体图片分享区分单张图片分享和多张图片分享,详情请看代码: import android.content.ComponentName; import android.content

android 调用系统分享图片及文字

调用系统分享文字:public static void shareText(Context context, String extraText) {Intent intent = new Intent(Intent.ACTION_SEND);intent.setType("text/plain");intent.putExtra(Intent.EXTRA_SUBJECT, "连接分享");intent.putExtra(Intent.EXTRA_TEXT, extr

Android调用系统分享分享内容到其他应用,不使用系统的ActionBar的弹窗,完全自定义

Android分享内容到其他应用,调用系统的Dialog或者ActionBar的弹窗都不太自由,限制太大,这里我提供一个完全自定界面的,可以弹窗,也可以直接在Activity或者Fragment里边自定义界面.这里展示一个关键类的代码,做了封装处理,我写两个一个Demo,免费源码在:http://download.csdn.net/detail/yanzhenjie1003/8565449 /** * @author YOLANDA * @Time 2015年4月5日 下午1:03:11 */

Android调用系统相机功能

在常规应用开发过程中,我们经常会使用到手机的相机功能,通过调用系统相机方便快捷的帮助我们实现拍照功能,本篇我将带领大家实现一下,如何通过调用系统相机实现拍照. 第一种:调用系统相机拍照,通过返回的照片缩略图展示我们的拍照图片 打开系统相机: Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, TAKE_PICTURE);// 如果用Activity.RESULT_O

调用系统分享功能

//分享文字 Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, "要分享的文本."); intent.setType("text/plain"); startActivity(Intent.createChooser(intent, "分享")); //分享图片 Uri uri = Uri.fromFile(new File(&qu

android调用系统的分享功能实现分享到短信,邮件和其他

之前写过一篇文章利用友盟等第三方实现分享到微信,微博和豆瓣等第三方社交站点.本次我们利用系统自带的分享功能去做,虽然简单,但对于以前类似友盟等第三方社交分享组件还没做的成熟的时候,也是一种好的选择.所以这里直接上代码对系统分享做个记录,代码有必要注释,所以就不做啥说明了: /** * 弹出分享列表 */ private void showShareDialog(){ AlertDialog.Builder builder = new AlertDialog.Builder(Thread_Cont

Android调用系统相机、自定义相机、处理大图片

Android调用系统相机和自定义相机实例 本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显示出来,该例子也会涉及到Android加载大图片时候的处理(避免OOM),还有简要提一下有些人SurfaceView出现黑屏的原因. Android应用拍照的两种方式,下面为两种形式的Demo展示出来的效果.    知识点: 一.调用系统自带的相机应用 二.自定义我们自己的拍照界面 三.关于计算机解析图片原理(如何正确加载图片到Android应用中) 所需