Android 调用系统的分享界面,进行文件分享

 //分享文字  
    public void shareText(View view) {  
        Intent shareIntent = new Intent();  
        shareIntent.setAction(Intent.ACTION_SEND);  
        shareIntent.putExtra(Intent.EXTRA_TEXT, "text内容.");  
        shareIntent.setType("text/plain");  
  
        //设置标题(弹出分享列表的界面标题),
        startActivity(Intent.createChooser(shareIntent, "分享到"));  
    }  
  
    //分享一张图片  
    public void shareSingleImage(View view) {  
        String imagePath = Environment.getExternalStorageDirectory() + File.separator + "aaa.jpg";  
        //由文件得到uri  
        Uri imageUri = Uri.fromFile(new File(imagePath));  //imagePath--本地的文件路径
        Log.d("share", "uri:" + imageUri);  
  
        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(filePath+"aaa-1.jpg")));  
        uriList.add(Uri.fromFile(new File(filePath+"aaa-2.jpg")));  
        uriList.add(Uri.fromFile(new File(filePath+"aaa-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, "分享到:"));  
    }  

}  


//分享所有类型文件:

 Intent shareIntent = new Intent(Intent.ACTION_SEND);
 shareIntent.putExtra(Intent.EXTRA_STREAM,
 Uri.fromFile(new File(filePath)));
 shareIntent.setType("*/*");//此处可发送多种文件
 startActivity(Intent.createChooser(shareIntent, “分享到:”));





猜你喜欢

转载自blog.csdn.net/yuzhidao/article/details/75267627
今日推荐