-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSystemShareUtils.java
More file actions
121 lines (99 loc) · 4.18 KB
/
SystemShareUtils.java
File metadata and controls
121 lines (99 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.realmo.utils;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import java.io.File;
import java.util.ArrayList;
/**
* @author Realmo
* @version 1.0.0
* @name SystemShareUtils
* @email momo.weiye@gmail.com
* @time 2018/1/5 14:43
* @describe 调用系统的分享功能(请确保传入的filePath exist)
*/
public class SystemShareUtils {
// //传文字
// public static void shareString(Context context,String title,String str) {
// Intent shareIntent = new Intent();
// shareIntent.setAction(Intent.ACTION_SEND);
// shareIntent.putExtra(Intent.EXTRA_TEXT, str);
// shareIntent.setType("text/plain");
// //设置分享列表的标题,并且每次都显示分享列表
// context.startActivity(Intent.createChooser(shareIntent, title));
// }
//传文本文件
public static void shareTextFile(Context context,String title,String filePath) {
//由文件得到uri
Uri fileUri = Uri.fromFile(new File(filePath));
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
shareIntent.setType("*/*");
context.startActivity(Intent.createChooser(shareIntent, title));
}
//传单图
public static void shareSingleImage(Context context,String title,String imagePath) {
//由文件得到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/*");
context.startActivity(Intent.createChooser(shareIntent, "分享到"));
}
// //传多图
// public static void shareMoreImage(Context context,String title,String...paths) {
//
// ArrayList<Uri> uriList = new ArrayList<>();
//
// //demo code
//// String path = Environment.getExternalStorageDirectory() + File.separator;
//// uriList.add(Uri.fromFile(new File(path+"head.jpg")));
//// uriList.add(Uri.fromFile(new File(path+"test.jpg")));
//
// for(String path:paths){
// uriList.add(Uri.fromFile(new File(path)));
// }
//
// Intent shareIntent = new Intent();
// shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
// shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
// shareIntent.setType("image/*");
// context.startActivity(Intent.createChooser(shareIntent, title));
// }
//传多图
public static void shareMoreImage(Context context,int titleResId,String...paths) {
ArrayList<Uri> uriList = new ArrayList<>();
//demo code
// String path = Environment.getExternalStorageDirectory() + File.separator;
// uriList.add(Uri.fromFile(new File(path+"head.jpg")));
// uriList.add(Uri.fromFile(new File(path+"test.jpg")));
for(String path:paths){
uriList.add(Uri.fromFile(new File(path)));
}
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
shareIntent.setType("image/*");
context.startActivity(Intent.createChooser(shareIntent, context.getResources().getString(titleResId)));
}
//传多图
public static void shareMoreImage(Context context, int titleResId, ArrayList<Uri> uriList) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
shareIntent.setType("image/*");
context.startActivity(Intent.createChooser(shareIntent, context.getResources().getString(titleResId)));
}
//传zip
public static void shareZip(Context context,String title,String zipPath) {
//由文件得到uri
Uri fileUri = Uri.fromFile(new File(zipPath));
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
shareIntent.setType("*/*");
context.startActivity(Intent.createChooser(shareIntent, title));
}
}