Commit 1a8cd127fc726fb3bc4a3881dc2a9a9bf3d47b2a

Authored by 袁思汶
1 parent 05b88d37

fourth

OutSide_Share/src/main/java/com/cnlive/outside_share/activity/ShareMomentActivity.java
1 package com.cnlive.outside_share.activity; 1 package com.cnlive.outside_share.activity;
2 2
3 -import android.app.Activity;  
4 import android.content.ContentUris; 3 import android.content.ContentUris;
5 import android.content.Context; 4 import android.content.Context;
6 import android.content.Intent; 5 import android.content.Intent;
7 import android.content.SharedPreferences; 6 import android.content.SharedPreferences;
8 -import android.content.pm.PackageManager;  
9 -import android.content.pm.ResolveInfo;  
10 import android.database.Cursor; 7 import android.database.Cursor;
11 -import android.graphics.Bitmap;  
12 import android.media.MediaPlayer; 8 import android.media.MediaPlayer;
13 import android.net.Uri; 9 import android.net.Uri;
14 import android.os.Build; 10 import android.os.Build;
@@ -16,7 +12,6 @@ import android.os.Bundle; @@ -16,7 +12,6 @@ import android.os.Bundle;
16 import android.os.Environment; 12 import android.os.Environment;
17 import android.provider.DocumentsContract; 13 import android.provider.DocumentsContract;
18 import android.provider.MediaStore; 14 import android.provider.MediaStore;
19 -import android.provider.Settings;  
20 import android.text.TextUtils; 15 import android.text.TextUtils;
21 import android.util.Log; 16 import android.util.Log;
22 17
@@ -31,7 +26,6 @@ import com.cnlive.libs.base.util.ShareReleaseInfoUtil; @@ -31,7 +26,6 @@ import com.cnlive.libs.base.util.ShareReleaseInfoUtil;
31 import com.cnlive.libs.base.util.StringUtils; 26 import com.cnlive.libs.base.util.StringUtils;
32 import com.cnlive.media.picker.entity.Media; 27 import com.cnlive.media.picker.entity.Media;
33 import com.cnlive.media.picker.utils.AndroidQUtil; 28 import com.cnlive.media.picker.utils.AndroidQUtil;
34 -import com.cnlive.media.picker.utils.BrandUtils;  
35 import com.cnlive.outside_share.R; 29 import com.cnlive.outside_share.R;
36 import com.cnlive.outside_share.util.FileType; 30 import com.cnlive.outside_share.util.FileType;
37 import com.cnlive.outside_share.util.FileUtil; 31 import com.cnlive.outside_share.util.FileUtil;
@@ -67,70 +61,35 @@ import androidx.appcompat.app.AppCompatActivity; @@ -67,70 +61,35 @@ import androidx.appcompat.app.AppCompatActivity;
67 @Route(path = "/out/ShareMomentActivity") 61 @Route(path = "/out/ShareMomentActivity")
68 public class ShareMomentActivity extends AppCompatActivity { 62 public class ShareMomentActivity extends AppCompatActivity {
69 63
70 -  
71 private File filevideo; 64 private File filevideo;
72 - private String textUri = "";  
73 - private String text = "";  
74 - private String screenShot = "";  
75 - private String subject = "";  
76 private SharedPreferences preferences; 65 private SharedPreferences preferences;
77 private Timer timer; 66 private Timer timer;
78 - private String chromePath;  
79 - private String chromeName;  
80 - private long chromeLength;  
81 - private boolean isQ;  
82 - private String clipDataImg = "";  
83 - private String type, action,outTyp; 67 + private String type, action, outTyp;
84 private Bundle bundle; 68 private Bundle bundle;
85 private String TEXT = "android.intent.extra.TEXT"; 69 private String TEXT = "android.intent.extra.TEXT";
86 private String SUBJECT = "android.intent.extra.SUBJECT"; 70 private String SUBJECT = "android.intent.extra.SUBJECT";
87 private ArrayList<String> mutil; 71 private ArrayList<String> mutil;
88 -  
89 - public static void start(Context context, String type, Bundle bundle, String action, ArrayList<String> arrayList,String outType,String outTypeUri) {  
90 - Intent intent = new Intent(context, ShareMomentActivity.class);  
91 - intent.putExtra("type", type);  
92 - intent.putExtra("bundle", bundle);  
93 - intent.putExtra("action",action);  
94 - intent.putStringArrayListExtra("mutil", arrayList);  
95 - intent.putExtra("outType",outType);  
96 - intent.putExtra("outTypeUri",outTypeUri);  
97 - context.startActivity(intent);  
98 - }  
99 - 72 + String pathreal = "";
  73 + private boolean equals;
100 74
101 @RequiresApi(api = Build.VERSION_CODES.KITKAT) 75 @RequiresApi(api = Build.VERSION_CODES.KITKAT)
102 @Override 76 @Override
103 protected void onCreate(@Nullable Bundle savedInstanceState) { 77 protected void onCreate(@Nullable Bundle savedInstanceState) {
104 super.onCreate(savedInstanceState); 78 super.onCreate(savedInstanceState);
105 setContentView(R.layout.sharemoment); 79 setContentView(R.layout.sharemoment);
106 - AlertUtil.showDeftToast(this,"进入页面"); 80 + AlertUtil.showDeftToast(this, "进入页面"); // todo Delete
107 timer = new Timer(); 81 timer = new Timer();
108 type = getIntent().getStringExtra("type"); 82 type = getIntent().getStringExtra("type");
109 bundle = getIntent().getBundleExtra("bundle"); 83 bundle = getIntent().getBundleExtra("bundle");
110 action = getIntent().getStringExtra("action"); 84 action = getIntent().getStringExtra("action");
111 mutil = getIntent().getStringArrayListExtra("mutil"); 85 mutil = getIntent().getStringArrayListExtra("mutil");
112 outTyp = getIntent().getStringExtra("outType"); 86 outTyp = getIntent().getStringExtra("outType");
113 -  
114 checkIntent(); 87 checkIntent();
115 } 88 }
116 89
117 - private void killTime() {  
118 - timer.schedule(new TimerTask() {  
119 - @Override  
120 - public void run() {  
121 - finish();  
122 - }  
123 - }, 5000);  
124 - }  
125 -  
126 - @Override  
127 - protected void onDestroy() {  
128 - super.onDestroy();  
129 - if (timer != null) timer.cancel();  
130 - }  
131 -  
132 @RequiresApi(api = Build.VERSION_CODES.KITKAT) 90 @RequiresApi(api = Build.VERSION_CODES.KITKAT)
133 public void checkIntent() { 91 public void checkIntent() {
  92 + equals = "shareMom".equals(outTyp); ////是否二次登陆 以下所有type均需要判断是否二次登录
134 if (bundle != null && action != null) { 93 if (bundle != null && action != null) {
135 switch (action) { 94 switch (action) {
136 case Intent.ACTION_SEND: 95 case Intent.ACTION_SEND:
@@ -146,22 +105,10 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -146,22 +105,10 @@ public class ShareMomentActivity extends AppCompatActivity {
146 } 105 }
147 } 106 }
148 107
149 - private String getPath(String cachePath) {  
150 - String path = (isQ ? this.getExternalFilesDir("") : Environment.getExternalStorageDirectory()) + cachePath;  
151 - File file = new File(path);  
152 - if (file.mkdirs()) {  
153 - return path;  
154 - }  
155 - return path;  
156 - }  
157 -  
158 - String pathreal = "";  
159 -  
160 - @RequiresApi(api = Build.VERSION_CODES.KITKAT)  
161 - private void jumpToSend( Context context, String type, Bundle bundle) { 108 + @RequiresApi(api = Build.VERSION_CODES.KITKAT) //单发
  109 + private void jumpToSend(Context context, String type, Bundle bundle) {
  110 + preferences = this.getSharedPreferences("OutShare", MODE_PRIVATE); //IM重连前存储信息
162 File filelogo = new File(getPath("/strike/cache/") + "sharefirst.jpg"); 111 File filelogo = new File(getPath("/strike/cache/") + "sharefirst.jpg");
163 - preferences = this.getSharedPreferences("OutShare", MODE_PRIVATE);  
164 -  
165 if (!filelogo.exists()) { 112 if (!filelogo.exists()) {
166 new Thread() { 113 new Thread() {
167 @Override 114 @Override
@@ -182,31 +129,29 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -182,31 +129,29 @@ public class ShareMomentActivity extends AppCompatActivity {
182 AlertUtil.showDeftToast(this, "数据获取异常,暂不支持此机型分享."); 129 AlertUtil.showDeftToast(this, "数据获取异常,暂不支持此机型分享.");
183 killTime(); 130 killTime();
184 } else if (type.startsWith("text/")) { 131 } else if (type.startsWith("text/")) {
185 - //case "text/plain":  
186 String link; 132 String link;
187 -  
188 - Uri textUri = "shareMom".equals(outTyp) ? Uri.parse(preferences.getString("extrastream", "")) : (Uri) bundle.getParcelable(Intent.EXTRA_STREAM); 133 + Uri textUri = equals ? Uri.parse(preferences.getString("extrastream", "")) : (Uri) bundle.getParcelable(Intent.EXTRA_STREAM);
189 if (textUri == null || TextUtils.isEmpty(textUri.toString())) { 134 if (textUri == null || TextUtils.isEmpty(textUri.toString())) {
190 - if ("shareMom".equals(outTyp)) { 135 + if (equals) {
191 link = preferences.getString("extratext", ""); 136 link = preferences.getString("extratext", "");
192 } else { 137 } else {
193 - link = bundle.get(TEXT).toString(); 138 + link = bundle.get(TEXT) == null ? "" : bundle.get(TEXT) + "";
194 } 139 }
195 140
196 - if (!TextUtils.isEmpty(link)) {  
197 - if (link.startsWith("http")) {  
198 - Uri screenShot = "shareMom".equals(outTyp) ? Uri.parse(preferences.getString("share_screenshot_as_stream", "")) : (Uri) bundle.getParcelable("share_screenshot_as_stream");  
199 - if (screenShot == null) { 141 + if (!StringUtils.isEmpty(link)) {
  142 + if (link.startsWith("http")) { //链接类型
  143 + Uri screenShot = equals ? Uri.parse(preferences.getString("share_screenshot_as_stream", "")) : (Uri) bundle.getParcelable("share_screenshot_as_stream");
  144 + if (screenShot == null) { //二次登录链接类型不带截图
200 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance(); 145 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
201 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML); 146 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
202 shareConfig.setImage(AppConfig.getShareLink()); 147 shareConfig.setImage(AppConfig.getShareLink());
203 shareConfig.setSubTitle(""); 148 shareConfig.setSubTitle("");
204 - shareConfig.setTitle(("shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? "链接" : "shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT).toString()); 149 + shareConfig.setTitle((equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? "链接" : equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT) + "");
205 shareConfig.setUrl(link); 150 shareConfig.setUrl(link);
206 shareConfig.shareRelease(this); 151 shareConfig.shareRelease(this);
207 finish(); 152 finish();
208 } else { 153 } else {
209 - if (link.contains("mp.weixin.qq.com")) { 154 + if (link.contains("mp.weixin.qq.com")) { //微信公众号类型链接
210 new Thread(new Runnable() { 155 new Thread(new Runnable() {
211 @Override 156 @Override
212 public void run() { 157 public void run() {
@@ -215,55 +160,53 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -215,55 +160,53 @@ public class ShareMomentActivity extends AppCompatActivity {
215 Document document = null; 160 Document document = null;
216 try { 161 try {
217 document = connect.get(); 162 document = connect.get();
218 - } catch (IOException e) {  
219 - e.printStackTrace();  
220 - }  
221 - Elements as = document.getElementsByTag("img");  
222 - if (document.getElementsByTag("h2") != null) {  
223 - if (document.getElementsByTag("h2").size() > 0) {  
224 - String h2 = document.getElementsByTag("h2").get(0).ownText();  
225 - shareConfig.setTitle(h2 == null ? ("shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? "链接" : "shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT).toString() : h2); 163 + Elements as = document.getElementsByTag("img");
  164 + if (document.getElementsByTag("h2") != null) {
  165 + if (document.getElementsByTag("h2").size() > 0) {
  166 + String h2 = document.getElementsByTag("h2").get(0).ownText();
  167 + shareConfig.setTitle(h2 == null ? (equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? "链接" : equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT) + "" : h2);
  168 + } else {
  169 + shareConfig.setTitle((equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? "链接" : equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT) + "");
  170 + }
226 } else { 171 } else {
227 - shareConfig.setTitle(("shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? "链接" : "shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT).toString()); 172 + shareConfig.setTitle((equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? "链接" : equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT) + "");
228 } 173 }
229 - } else {  
230 - shareConfig.setTitle(("shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? "链接" : "shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT).toString());  
231 - }  
232 - if (as != null) {  
233 - for (int i = 0; i < as.size(); i++) {  
234 - Element element = as.get(i);  
235 - String type = element.attr("data-type");  
236 - if (type != null && !"gif".equals(type) && !StringUtils.isEmpty(type) && !element.attr("data-src").endsWith("gif")) {  
237 - String src = element.attr("data-src");  
238 - shareConfig.setImage(src == null ? AppConfig.getShareLink() : src);  
239 - break; 174 + if (as != null) {
  175 + for (int i = 0; i < as.size(); i++) {
  176 + Element element = as.get(i);
  177 + String type = element.attr("data-type");
  178 + if (type != null && !"gif".equals(type) && !StringUtils.isEmpty(type) && !element.attr("data-src").endsWith("gif")) {
  179 + String src = element.attr("data-src");
  180 + shareConfig.setImage(src == null ? AppConfig.getShareLink() : src);
  181 + break;
  182 + }
240 } 183 }
  184 + } else {
  185 + shareConfig.setImage(AppConfig.getShareLink());
241 } 186 }
242 - } else {  
243 - shareConfig.setImage(AppConfig.getShareLink()); 187 + shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
  188 + shareConfig.setSubTitle("");
  189 + shareConfig.setUrl(link);
  190 + shareConfig.shareRelease(context);
  191 + finish();
  192 + } catch (IOException e) {
  193 + e.printStackTrace();
244 } 194 }
245 - shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);  
246 - shareConfig.setSubTitle("");  
247 - shareConfig.setUrl(link);  
248 - shareConfig.shareRelease(context);  
249 - finish();  
250 } 195 }
251 }).start(); 196 }).start();
252 - } else {  
253 - if (("shareMom".equals(outTyp))) { 197 + } else { //普通连接类型
  198 + if (equals) { //二次登录
254 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance(); 199 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
255 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML); 200 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
256 shareConfig.setImage(AppConfig.getShareLink()); 201 shareConfig.setImage(AppConfig.getShareLink());
257 shareConfig.setSubTitle(""); 202 shareConfig.setSubTitle("");
258 - shareConfig.setTitle(("shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? "链接" : "shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT).toString()); 203 + shareConfig.setTitle(preferences.getString(SUBJECT, ""));
259 shareConfig.setUrl(link); 204 shareConfig.setUrl(link);
260 shareConfig.shareRelease(context); 205 shareConfig.shareRelease(context);
261 finish(); 206 finish();
262 - } else { 207 + } else { //首次登录
263 try { 208 try {
264 - //授权Uri的读取权限  
265 - //若不授权,在 Android 6.0 以上测试崩溃  
266 - //第一个参数为需要授权的apk包名 209 + //授权Uri的读取权限 若不授权,在 Android 6.0 以上测试崩溃 第一个参数为需要授权的apk包名
267 grantUriPermission("com.cnlive.strike", screenShot, Intent.FLAG_GRANT_READ_URI_PERMISSION); 210 grantUriPermission("com.cnlive.strike", screenShot, Intent.FLAG_GRANT_READ_URI_PERMISSION);
268 //通过 Uri 获取截屏图片的输入流 211 //通过 Uri 获取截屏图片的输入流
269 InputStream is = getContentResolver().openInputStream(screenShot); 212 InputStream is = getContentResolver().openInputStream(screenShot);
@@ -283,26 +226,26 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -283,26 +226,26 @@ public class ShareMomentActivity extends AppCompatActivity {
283 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML); 226 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
284 shareConfig.setImage(AppConfig.getShareLink()); 227 shareConfig.setImage(AppConfig.getShareLink());
285 shareConfig.setSubTitle(""); 228 shareConfig.setSubTitle("");
286 - shareConfig.setTitle(("shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? "链接" : "shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT).toString()); 229 + shareConfig.setTitle(bundle.get(SUBJECT) == null ? "链接" : bundle.get(SUBJECT) + "");
287 shareConfig.setUrl(link); 230 shareConfig.setUrl(link);
288 shareConfig.shareRelease(context); 231 shareConfig.shareRelease(context);
289 finish(); 232 finish();
290 } 233 }
291 } 234 }
292 } 235 }
293 - } else if (!link.startsWith("http") && !link.contains("http") && link.length() > 0) { 236 + } else if (!link.startsWith("http") && !link.contains("http") && link.length() > 0) { //文字实体类型
294 jumpReleaseActivity(context, new ArrayList<Media>(), 3, link, "nocircle"); 237 jumpReleaseActivity(context, new ArrayList<Media>(), 3, link, "nocircle");
295 finish(); 238 finish();
296 - } else if (link.contains("http") && !link.startsWith("http")) { 239 + } else if (link.contains("http") && !link.startsWith("http")) { //带文字实体前缀的复合类型链接
297 String linkcontext = link.replaceAll("\\s*", ""); 240 String linkcontext = link.replaceAll("\\s*", "");
298 - int end; 241 + int end; //截取前缀文字作为分享标题内容 ,后半段为链接link内容
299 int begin = linkcontext.indexOf("http"); 242 int begin = linkcontext.indexOf("http");
300 if (linkcontext.contains("(")) { 243 if (linkcontext.contains("(")) {
301 end = linkcontext.indexOf("("); 244 end = linkcontext.indexOf("(");
302 } else { 245 } else {
303 end = linkcontext.length(); 246 end = linkcontext.length();
304 } 247 }
305 - String file = getIntent().getExtras().getString("file"); 248 + String file = bundle.getString("file");
306 FileUtil.copyFile(file, getPath("/strike/cache/") + "share.jpg"); 249 FileUtil.copyFile(file, getPath("/strike/cache/") + "share.jpg");
307 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance(); 250 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
308 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML); 251 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
@@ -315,37 +258,37 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -315,37 +258,37 @@ public class ShareMomentActivity extends AppCompatActivity {
315 Document document = null; 258 Document document = null;
316 try { 259 try {
317 document = connect.get(); 260 document = connect.get();
318 - } catch (IOException e) {  
319 - e.printStackTrace();  
320 - }  
321 - Elements as = document.getElementsByTag("img");  
322 - if (document.getElementsByTag("h2") != null) {  
323 - if (document.getElementsByTag("h2").size() > 0) {  
324 - String h2 = document.getElementsByTag("h2").get(0).ownText();  
325 - shareConfig.setTitle(h2 == null ? ("shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? link.substring(0, begin) : "shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT).toString() : h2); 261 + Elements as = document.getElementsByTag("img");
  262 + if (document.getElementsByTag("h2") != null) {
  263 + if (document.getElementsByTag("h2").size() > 0) {
  264 + String h2 = document.getElementsByTag("h2").get(0).ownText();
  265 + shareConfig.setTitle(h2 == null ? (equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? link.substring(0, begin) : equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT) + "" : h2);
  266 + } else {
  267 + shareConfig.setTitle((equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? link.substring(0, begin) : equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT) + "");
  268 + }
326 } else { 269 } else {
327 - shareConfig.setTitle(("shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? link.substring(0, begin) : "shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT).toString()); 270 + shareConfig.setTitle((equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? link.substring(0, begin) : equals ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT) + "");
328 } 271 }
329 - } else {  
330 - shareConfig.setTitle(("shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT)) == null ? link.substring(0, begin) : "shareMom".equals(outTyp) ? preferences.getString(SUBJECT, "") : bundle.get(SUBJECT).toString());  
331 - }  
332 - if (as != null) {  
333 - for (int i = 0; i < as.size(); i++) {  
334 - Element element = as.get(i);  
335 - String type = element.attr("data-type");  
336 - if (type != null && !"gif".equals(type) && !StringUtils.isEmpty(type) && !element.attr("data-src").endsWith("gif")) {  
337 - String src = element.attr("data-src");  
338 - shareConfig.setImage(src == null ? AppConfig.getShareLink() : src);  
339 - break; 272 + if (as != null) {
  273 + for (int i = 0; i < as.size(); i++) {
  274 + Element element = as.get(i);
  275 + String type = element.attr("data-type");
  276 + if (type != null && !"gif".equals(type) && !StringUtils.isEmpty(type) && !element.attr("data-src").endsWith("gif")) {
  277 + String src = element.attr("data-src");
  278 + shareConfig.setImage(src == null ? AppConfig.getShareLink() : src);
  279 + break;
  280 + }
340 } 281 }
  282 + } else {
  283 + shareConfig.setImage(AppConfig.getShareLink());
341 } 284 }
342 - } else {  
343 - shareConfig.setImage(AppConfig.getShareLink()); 285 + shareConfig.setSubTitle("");
  286 + shareConfig.setUrl(jsouplink);
  287 + shareConfig.shareRelease(context);
  288 + finish();
  289 + } catch (IOException e) {
  290 + e.printStackTrace();
344 } 291 }
345 - shareConfig.setSubTitle("");  
346 - shareConfig.setUrl(jsouplink);  
347 - shareConfig.shareRelease(context);  
348 - finish();  
349 } 292 }
350 }).start(); 293 }).start();
351 } else { 294 } else {
@@ -357,25 +300,22 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -357,25 +300,22 @@ public class ShareMomentActivity extends AppCompatActivity {
357 finish(); 300 finish();
358 } 301 }
359 } else { 302 } else {
360 - AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享.");  
361 - killTime(); 303 + canNotDo();
362 } 304 }
363 } else { 305 } else {
364 - AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享.");  
365 - killTime(); 306 + canNotDo();
366 } 307 }
367 } else { 308 } else {
368 - AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享");  
369 - killTime(); 309 + canNotDo();
370 } 310 }
371 } else if (type.startsWith("image/")) { 311 } else if (type.startsWith("image/")) {
372 //兼容QQ浏览器链接类型 312 //兼容QQ浏览器链接类型
373 if (bundle.get(TEXT) != null && bundle.getParcelable(Intent.EXTRA_STREAM) == null) { 313 if (bundle.get(TEXT) != null && bundle.getParcelable(Intent.EXTRA_STREAM) == null) {
374 - if (bundle.get(TEXT).toString().contains("@QQ浏览器") || bundle.get(TEXT).toString().contains("html5.qq.com") || bundle.get(TEXT).toString().contains("mbrowser.baidu.com")) {  
375 - String qqLink = bundle.get(TEXT).toString().substring(bundle.get(TEXT).toString().indexOf("http"));  
376 - String qqTitle = bundle.get(TEXT).toString().substring(0, bundle.get(TEXT).toString().indexOf("http"));  
377 - Uri imageUri = "shareMom".equals(outTyp) ? Uri.parse(preferences.getString("extrastream", "")) : bundle.getParcelable(Intent.EXTRA_STREAM);  
378 - //String qqPic = getPath(context, imageUri); 314 + String bundleText = bundle.get(TEXT) + "";
  315 + if (bundleText.contains("@QQ浏览器") || bundleText.contains("html5.qq.com") || bundleText.contains("mbrowser.baidu.com")) {
  316 + String qqLink = bundleText.substring(bundleText.indexOf("http"));
  317 + String qqTitle = bundleText.substring(0, bundleText.indexOf("http"));
  318 + Uri imageUri = equals ? Uri.parse(preferences.getString("extrastream", "")) : bundle.getParcelable(Intent.EXTRA_STREAM);
379 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance(); 319 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
380 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML); 320 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
381 shareConfig.setImage(AppConfig.getShareLink()); 321 shareConfig.setImage(AppConfig.getShareLink());
@@ -385,10 +325,10 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -385,10 +325,10 @@ public class ShareMomentActivity extends AppCompatActivity {
385 shareConfig.shareRelease(context); 325 shareConfig.shareRelease(context);
386 finish(); 326 finish();
387 } 327 }
388 - } else if (bundle.get(TEXT) == null && bundle.get("weixin_text") != null && bundle.get("weixin_text").toString().contains("liebao.cn")) {  
389 - String weixin_text = bundle.get("weixin_text").toString().substring(bundle.get("weixin_text").toString().indexOf("http"));  
390 - String weixin_title = bundle.get("weixin_title").toString();  
391 - String weixin_img_url = bundle.get("weixin_img_url").toString(); 328 + } else if (bundle.get(TEXT) == null && bundle.get("weixin_text") != null && (bundle.get("weixin_text") + "").contains("liebao.cn")) { //兼容舔狗猎豹浏览器内置图片分享问题
  329 + String weixin_text = (bundle.get("weixin_text") + "").substring((bundle.get("weixin_text") + "").indexOf("http"));
  330 + String weixin_title = bundle.get("weixin_title") + "";
  331 + String weixin_img_url = bundle.get("weixin_img_url") + "";
392 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance(); 332 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
393 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML); 333 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
394 shareConfig.setImage(weixin_img_url); 334 shareConfig.setImage(weixin_img_url);
@@ -398,7 +338,7 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -398,7 +338,7 @@ public class ShareMomentActivity extends AppCompatActivity {
398 shareConfig.shareRelease(context); 338 shareConfig.shareRelease(context);
399 finish(); 339 finish();
400 } else { 340 } else {
401 - Uri imageUri = "shareMom".equals(outTyp) ? Uri.parse(preferences.getString("extrastream", "")) : bundle.getParcelable(Intent.EXTRA_STREAM); 341 + Uri imageUri = equals ? Uri.parse(preferences.getString("extrastream", "")) : bundle.getParcelable(Intent.EXTRA_STREAM);
402 if ("image/gif".equals(type) || "image/vnd.wap.wbmp".equals(type) || imageUri == null) { 342 if ("image/gif".equals(type) || "image/vnd.wap.wbmp".equals(type) || imageUri == null) {
403 if (DoublePressed.onDoublePressed()) return; 343 if (DoublePressed.onDoublePressed()) return;
404 AlertUtil.showDeftToast(context, "网家家暂不支持此格式图片分享."); 344 AlertUtil.showDeftToast(context, "网家家暂不支持此格式图片分享.");
@@ -407,10 +347,10 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -407,10 +347,10 @@ public class ShareMomentActivity extends AppCompatActivity {
407 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, imageUri)); 347 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, imageUri));
408 String pathreal = getPath(context, imageUri); 348 String pathreal = getPath(context, imageUri);
409 String fileType = FileType.getFileType(pathreal); 349 String fileType = FileType.getFileType(pathreal);
410 - if ("wbmp".equals(fileType)) { 350 + if ("wbmp".equals(fileType) || pathreal == null) {
411 AlertUtil.showDeftToast(context, "网家家暂不支持此格式图片分享."); 351 AlertUtil.showDeftToast(context, "网家家暂不支持此格式图片分享.");
412 killTime(); 352 killTime();
413 - } else if ("video".equals(fileType) || "avi".equals(fileType)) { 353 + } else if ("video".equals(fileType) || "avi".equals(fileType)) { //兼容部分浏览器视频类型文件以图片type封装intent传递
414 filevideo = new File(pathreal); //pic 1 video 3 354 filevideo = new File(pathreal); //pic 1 video 3
415 MediaPlayer mediaPlayer = new MediaPlayer(); 355 MediaPlayer mediaPlayer = new MediaPlayer();
416 try { 356 try {
@@ -430,19 +370,17 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -430,19 +370,17 @@ public class ShareMomentActivity extends AppCompatActivity {
430 jumpReleaseActivity(context, medialist, 3, "", "nocircle"); 370 jumpReleaseActivity(context, medialist, 3, "", "nocircle");
431 finish(); 371 finish();
432 } 372 }
433 - } else if (("jpg".equals(fileType) || "png".equals(fileType)) && !(imageUri + "").contains("com.tencent.mtt")) {  
434 - File file = new File(pathreal); //pic 1 video 3 373 + } else if (("jpg".equals(fileType) || "png".equals(fileType)) && !(imageUri + "").contains("com.tencent.mtt")) { //媒体文件类型混乱问题处理 //pic 1 video 3
  374 + File file = new File(pathreal);
435 ArrayList<Media> medialist = new ArrayList<>(); 375 ArrayList<Media> medialist = new ArrayList<>();
436 Media media = new Media(file.getPath(), file.getName(), 1, 1, file.length(), 0, "", ""); 376 Media media = new Media(file.getPath(), file.getName(), 1, 1, file.length(), 0, "", "");
437 medialist.add(media); 377 medialist.add(media);
438 jumpReleaseActivity(context, medialist, 3, "", "nocircle"); 378 jumpReleaseActivity(context, medialist, 3, "", "nocircle");
439 finish(); 379 finish();
440 - } else if (("shareMom".equals(outTyp) ? preferences.getString("extratext", null) : bundle.get(TEXT)) != null && 380 + } else if ((equals ? preferences.getString("extratext", null) : bundle.get(TEXT)) != null &&
441 bundle.get(TEXT) != null && !(bundle.get(TEXT) + "").contains("http")) { //腾讯文件Android Q 381 bundle.get(TEXT) != null && !(bundle.get(TEXT) + "").contains("http")) { //腾讯文件Android Q
442 String pathImg = getPath(context, imageUri); 382 String pathImg = getPath(context, imageUri);
443 Uri mediaUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 383 Uri mediaUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
444 -  
445 -  
446 String[] projection = {MediaStore.Images.Media._ID, 384 String[] projection = {MediaStore.Images.Media._ID,
447 MediaStore.Images.Media.DATA, 385 MediaStore.Images.Media.DATA,
448 MediaStore.Images.Media.DATE_ADDED, 386 MediaStore.Images.Media.DATE_ADDED,
@@ -453,7 +391,6 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -453,7 +391,6 @@ public class ShareMomentActivity extends AppCompatActivity {
453 MediaStore.Images.Media.DISPLAY_NAME + "= ?", 391 MediaStore.Images.Media.DISPLAY_NAME + "= ?",
454 new String[]{pathImg.substring(pathImg.lastIndexOf("/") + 1)}, 392 new String[]{pathImg.substring(pathImg.lastIndexOf("/") + 1)},
455 null); 393 null);
456 -  
457 Uri uri = null; 394 Uri uri = null;
458 if (cursor != null && cursor.moveToFirst()) { 395 if (cursor != null && cursor.moveToFirst()) {
459 uri = ContentUris.withAppendedId(mediaUri, 396 uri = ContentUris.withAppendedId(mediaUri,
@@ -464,15 +401,13 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -464,15 +401,13 @@ public class ShareMomentActivity extends AppCompatActivity {
464 killTime(); 401 killTime();
465 } 402 }
466 if (cursor != null) cursor.close(); 403 if (cursor != null) cursor.close();
467 - } else if (("shareMom".equals(outTyp) ? preferences.getString("extratext", null) : bundle.get(TEXT)) != null && 404 + } else if ((equals ? preferences.getString("extratext", null) : bundle.get(TEXT)) != null &&
468 bundle.get(TEXT) != null && (bundle.get(TEXT) + "").contains("http")) { // Q浏览器分享图片类型 405 bundle.get(TEXT) != null && (bundle.get(TEXT) + "").contains("http")) { // Q浏览器分享图片类型
469 - String link = "shareMom".equals(outTyp) ? preferences.getString("extratext", "") : bundle.get(TEXT).toString(); 406 + String link = equals ? preferences.getString("extratext", "") : bundle.get(TEXT) + "";
470 if (link.contains("http") && !link.startsWith("http")) { 407 if (link.contains("http") && !link.startsWith("http")) {
471 int begin = link.indexOf("http"); 408 int begin = link.indexOf("http");
472 int end = link.length(); 409 int end = link.length();
473 - // if (imageUri.toString().contains("QQBrowser") && imageUri.toString().endsWith(".png")) {  
474 FileUtil.copyFile(imageUri.toString(), getPath("/strike/cache/") + "share.jpg"); 410 FileUtil.copyFile(imageUri.toString(), getPath("/strike/cache/") + "share.jpg");
475 - // }  
476 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance(); 411 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
477 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML); 412 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
478 shareConfig.setImage(AppConfig.getShareLink()); 413 shareConfig.setImage(AppConfig.getShareLink());
@@ -482,11 +417,8 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -482,11 +417,8 @@ public class ShareMomentActivity extends AppCompatActivity {
482 shareConfig.shareRelease(context); 417 shareConfig.shareRelease(context);
483 finish(); 418 finish();
484 } 419 }
485 - } else if (imageUri == null) {  
486 - AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享.");  
487 - killTime();  
488 - } else if (String.valueOf(imageUri).startsWith("content://")) {  
489 - if (("shareMom".equals(outTyp))) { 420 + } else if (String.valueOf(imageUri).startsWith("content://")) { //Chrome浏览器内置图片分享
  421 + if (equals) {
490 String chromePath = preferences.getString("chromePath", ""); 422 String chromePath = preferences.getString("chromePath", "");
491 String chromeName = preferences.getString("chromeName", ""); 423 String chromeName = preferences.getString("chromeName", "");
492 long chromeLength = preferences.getLong("chromeLength", 10); 424 long chromeLength = preferences.getLong("chromeLength", 10);
@@ -501,10 +433,9 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -501,10 +433,9 @@ public class ShareMomentActivity extends AppCompatActivity {
501 } else { 433 } else {
502 String pathImg = getPath(context, imageUri); 434 String pathImg = getPath(context, imageUri);
503 if (pathImg == null && !imageUri.toString().contains("QQBrowser") && !imageUri.toString().endsWith(".png")) { 435 if (pathImg == null && !imageUri.toString().contains("QQBrowser") && !imageUri.toString().endsWith(".png")) {
504 - AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享.");  
505 - killTime(); 436 + canNotDo();
506 } else { 437 } else {
507 - if (pathImg != null && pathImg.endsWith("wbmp")) { 438 + if (pathImg == null || pathImg.endsWith("wbmp")) {
508 AlertUtil.showDeftToast(this, "网家家暂不支持此格式图片分享."); 439 AlertUtil.showDeftToast(this, "网家家暂不支持此格式图片分享.");
509 killTime(); 440 killTime();
510 } else { 441 } else {
@@ -519,20 +450,15 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -519,20 +450,15 @@ public class ShareMomentActivity extends AppCompatActivity {
519 } 450 }
520 } 451 }
521 } 452 }
522 -  
523 } else if (type.startsWith("video/")) { 453 } else if (type.startsWith("video/")) {
524 - Uri videoUri = "shareMom".equals(outTyp) ? Uri.parse(preferences.getString("extrastream", "")) : bundle.getParcelable(Intent.EXTRA_STREAM); 454 + Uri videoUri = equals ? Uri.parse(preferences.getString("extrastream", "")) : bundle.getParcelable(Intent.EXTRA_STREAM);
525 if (videoUri == null) { 455 if (videoUri == null) {
526 - AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享.");  
527 - killTime(); 456 + canNotDo();
528 } else { 457 } else {
529 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, videoUri)); 458 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, videoUri));
530 if ((videoUri + "").contains("file://")) { 459 if ((videoUri + "").contains("file://")) {
531 -  
532 String pathImg = getPath(context, videoUri); 460 String pathImg = getPath(context, videoUri);
533 Uri mediaUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; 461 Uri mediaUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
534 -  
535 -  
536 String[] projection = {MediaStore.Video.Media._ID, 462 String[] projection = {MediaStore.Video.Media._ID,
537 MediaStore.Video.Media.DATA, 463 MediaStore.Video.Media.DATA,
538 MediaStore.Video.Media.DATE_ADDED, 464 MediaStore.Video.Media.DATE_ADDED,
@@ -543,8 +469,6 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -543,8 +469,6 @@ public class ShareMomentActivity extends AppCompatActivity {
543 MediaStore.Video.Media.DISPLAY_NAME + "= ?", 469 MediaStore.Video.Media.DISPLAY_NAME + "= ?",
544 new String[]{pathImg.substring(pathImg.lastIndexOf("/") + 1)}, 470 new String[]{pathImg.substring(pathImg.lastIndexOf("/") + 1)},
545 null); 471 null);
546 -  
547 - //Uri uriQ = null;  
548 if (cursor != null && cursor.moveToFirst()) { 472 if (cursor != null && cursor.moveToFirst()) {
549 videoUri = ContentUris.withAppendedId(mediaUri, 473 videoUri = ContentUris.withAppendedId(mediaUri,
550 cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID))); 474 cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID)));
@@ -594,17 +518,13 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -594,17 +518,13 @@ public class ShareMomentActivity extends AppCompatActivity {
594 518
595 private void startUriAddress(Context context, Uri imageUri) { 519 private void startUriAddress(Context context, Uri imageUri) {
596 String path = imageUri.getPath(); 520 String path = imageUri.getPath();
597 - Bitmap bitmap;  
598 InputStream is = null; 521 InputStream is = null;
599 String md5 = null; 522 String md5 = null;
600 int byteread = 0; 523 int byteread = 0;
601 String extension; 524 String extension;
602 -  
603 try { 525 try {
604 context.grantUriPermission(AppConfig.getAppPackeg(), imageUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); 526 context.grantUriPermission(AppConfig.getAppPackeg(), imageUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
605 is = context.getContentResolver().openInputStream(imageUri); 527 is = context.getContentResolver().openInputStream(imageUri);
606 -  
607 - //---  
608 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 528 ByteArrayOutputStream baos = new ByteArrayOutputStream();
609 byte[] buffer = new byte[1024]; 529 byte[] buffer = new byte[1024];
610 int len; 530 int len;
@@ -614,22 +534,15 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -614,22 +534,15 @@ public class ShareMomentActivity extends AppCompatActivity {
614 is.close(); 534 is.close();
615 baos.flush(); 535 baos.flush();
616 baos.close(); 536 baos.close();
617 -  
618 InputStream stream1 = new ByteArrayInputStream(baos.toByteArray()); 537 InputStream stream1 = new ByteArrayInputStream(baos.toByteArray());
619 InputStream stream2 = new ByteArrayInputStream(baos.toByteArray()); 538 InputStream stream2 = new ByteArrayInputStream(baos.toByteArray());
620 - //---  
621 -  
622 -  
623 md5 = MD5Util.getMD5(stream1); 539 md5 = MD5Util.getMD5(stream1);
624 stream1.close(); 540 stream1.close();
625 -  
626 - File appDir = new File(isQ ? this.getExternalFilesDir("") : Environment.getExternalStorageDirectory(), "strike");  
627 - 541 + File appDir = new File(AndroidQUtil.isAndroidQ() ? this.getExternalFilesDir("") : Environment.getExternalStorageDirectory(), "strike");
628 if (!appDir.exists()) appDir.mkdir(); 542 if (!appDir.exists()) appDir.mkdir();
629 543
630 extension = FileUtil.getExtensionName(path); 544 extension = FileUtil.getExtensionName(path);
631 extension = TextUtils.isEmpty(extension) ? "" : ("." + extension); 545 extension = TextUtils.isEmpty(extension) ? "" : ("." + extension);
632 -  
633 File file = new File(appDir, md5 + extension); 546 File file = new File(appDir, md5 + extension);
634 547
635 FileOutputStream fs = new FileOutputStream(file); 548 FileOutputStream fs = new FileOutputStream(file);
@@ -652,26 +565,6 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -652,26 +565,6 @@ public class ShareMomentActivity extends AppCompatActivity {
652 } 565 }
653 } 566 }
654 567
655 -  
656 - public static void settingPermissionActivity(Activity activity, int CODE_REQUEST_CAMERA_PERMISSIONS) {  
657 - //判断是否为小米系统  
658 - if (TextUtils.equals(BrandUtils.getSystemInfo().getOs(), BrandUtils.SYS_MIUI)) {  
659 - Intent miuiIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");  
660 - miuiIntent.putExtra("extra_pkgname", activity.getPackageName());  
661 - //检测是否有能接受该Intent的Activity存在  
662 - List<ResolveInfo> resolveInfos = activity.getPackageManager().queryIntentActivities(miuiIntent, PackageManager.MATCH_DEFAULT_ONLY);  
663 - if (resolveInfos.size() > 0) {  
664 - activity.startActivityForResult(miuiIntent, CODE_REQUEST_CAMERA_PERMISSIONS);  
665 - return;  
666 - }  
667 - }  
668 - //如果不是小米系统 则打开Android系统的应用设置页  
669 - Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);  
670 - Uri uri = Uri.fromParts("package", activity.getPackageName(), null);  
671 - intent.setData(uri);  
672 - activity.startActivityForResult(intent, CODE_REQUEST_CAMERA_PERMISSIONS);  
673 - }  
674 -  
675 public static String getFilePathFromURI(Context context, Uri contentUri) { 568 public static String getFilePathFromURI(Context context, Uri contentUri) {
676 String fileName = getFileName(contentUri); 569 String fileName = getFileName(contentUri);
677 if (!TextUtils.isEmpty(fileName)) { 570 if (!TextUtils.isEmpty(fileName)) {
@@ -759,26 +652,18 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -759,26 +652,18 @@ public class ShareMomentActivity extends AppCompatActivity {
759 652
760 @RequiresApi(api = Build.VERSION_CODES.KITKAT) 653 @RequiresApi(api = Build.VERSION_CODES.KITKAT)
761 public static String getPath(Context context, Uri uri) { 654 public static String getPath(Context context, Uri uri) {
762 -  
763 - final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;//sdk版本是否大于4.4  
764 -  
765 - // DocumentProvider  
766 - if (uri != null && isKitKat && DocumentsContract.isDocumentUri(context, uri)) {  
767 - // ExternalStorageProvider 655 + if (uri != null && DocumentsContract.isDocumentUri(context, uri)) {
768 if (isExternalStorageDocument(uri)) { 656 if (isExternalStorageDocument(uri)) {
769 final String docId = DocumentsContract.getDocumentId(uri); 657 final String docId = DocumentsContract.getDocumentId(uri);
770 final String[] split = docId.split(":"); 658 final String[] split = docId.split(":");
771 final String type = split[0]; 659 final String type = split[0];
772 -  
773 if ("primary".equalsIgnoreCase(type)) { 660 if ("primary".equalsIgnoreCase(type)) {
774 return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ? context.getExternalFilesDir("") : Environment.getExternalStorageDirectory()) + "/" + split[1]; 661 return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ? context.getExternalFilesDir("") : Environment.getExternalStorageDirectory()) + "/" + split[1];
775 } 662 }
776 } else if (isDownloadsDocument(uri)) { 663 } else if (isDownloadsDocument(uri)) {
777 -  
778 final String id = DocumentsContract.getDocumentId(uri); 664 final String id = DocumentsContract.getDocumentId(uri);
779 final Uri contentUri = ContentUris.withAppendedId( 665 final Uri contentUri = ContentUris.withAppendedId(
780 Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); 666 Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
781 -  
782 return getDataColumn(context, contentUri, null, null); 667 return getDataColumn(context, contentUri, null, null);
783 } 668 }
784 // MediaProvider 669 // MediaProvider
@@ -806,7 +691,6 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -806,7 +691,6 @@ public class ShareMomentActivity extends AppCompatActivity {
806 } 691 }
807 // MediaStore (and general) 692 // MediaStore (and general)
808 else if (uri != null && uri.getScheme() != null && "content".equalsIgnoreCase(uri.getScheme())) { 693 else if (uri != null && uri.getScheme() != null && "content".equalsIgnoreCase(uri.getScheme())) {
809 -  
810 // Return the remote address 694 // Return the remote address
811 if (isGooglePhotosUri(uri)) 695 if (isGooglePhotosUri(uri))
812 return uri.getLastPathSegment(); 696 return uri.getLastPathSegment();
@@ -817,7 +701,6 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -817,7 +701,6 @@ public class ShareMomentActivity extends AppCompatActivity {
817 else if (uri != null && uri.getScheme() != null && "file".equalsIgnoreCase(uri.getScheme())) { 701 else if (uri != null && uri.getScheme() != null && "file".equalsIgnoreCase(uri.getScheme())) {
818 return uri.getPath(); 702 return uri.getPath();
819 } 703 }
820 -  
821 return null; 704 return null;
822 } 705 }
823 706
@@ -840,7 +723,6 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -840,7 +723,6 @@ public class ShareMomentActivity extends AppCompatActivity {
840 723
841 public static String getDataColumn(Context context, Uri uri, String selection, 724 public static String getDataColumn(Context context, Uri uri, String selection,
842 String[] selectionArgs) { 725 String[] selectionArgs) {
843 -  
844 Cursor cursor = null; 726 Cursor cursor = null;
845 final String column = "_data"; 727 final String column = "_data";
846 final String[] projection = {column}; 728 final String[] projection = {column};
@@ -853,7 +735,7 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -853,7 +735,7 @@ public class ShareMomentActivity extends AppCompatActivity {
853 return cursor.getString(index); 735 return cursor.getString(index);
854 } 736 }
855 } catch (Exception e) { 737 } catch (Exception e) {
856 - Log.e("data主键找不到", e.getMessage()); 738 + Log.e("data主键找不到", e.getMessage() + "没有主键");
857 } finally { 739 } finally {
858 if (cursor != null) 740 if (cursor != null)
859 cursor.close(); 741 cursor.close();
@@ -869,7 +751,7 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -869,7 +751,7 @@ public class ShareMomentActivity extends AppCompatActivity {
869 killTime(); 751 killTime();
870 } else { 752 } else {
871 if (type.startsWith("image/")) { 753 if (type.startsWith("image/")) {
872 - if ("shareMom".equals(outTyp)) { 754 + if (equals) {
873 String clipDataImg = preferences.getString("clipDataImg", ""); 755 String clipDataImg = preferences.getString("clipDataImg", "");
874 Gson gson = new Gson(); 756 Gson gson = new Gson();
875 Type listType = new TypeToken<List<Media>>() { 757 Type listType = new TypeToken<List<Media>>() {
@@ -884,11 +766,8 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -884,11 +766,8 @@ public class ShareMomentActivity extends AppCompatActivity {
884 766
885 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri)); 767 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));
886 if ((uri + "").contains("file://")) { 768 if ((uri + "").contains("file://")) {
887 -  
888 String pathImg = getPath(context, uri); 769 String pathImg = getPath(context, uri);
889 Uri mediaUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 770 Uri mediaUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
890 -  
891 -  
892 String[] projection = {MediaStore.Images.Media._ID, 771 String[] projection = {MediaStore.Images.Media._ID,
893 MediaStore.Images.Media.DATA, 772 MediaStore.Images.Media.DATA,
894 MediaStore.Images.Media.DATE_ADDED, 773 MediaStore.Images.Media.DATE_ADDED,
@@ -899,8 +778,6 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -899,8 +778,6 @@ public class ShareMomentActivity extends AppCompatActivity {
899 MediaStore.Images.Media.DISPLAY_NAME + "= ?", 778 MediaStore.Images.Media.DISPLAY_NAME + "= ?",
900 new String[]{pathImg.substring(pathImg.lastIndexOf("/") + 1)}, 779 new String[]{pathImg.substring(pathImg.lastIndexOf("/") + 1)},
901 null); 780 null);
902 -  
903 - //Uri uriQ = null;  
904 if (cursor != null && cursor.moveToFirst()) { 781 if (cursor != null && cursor.moveToFirst()) {
905 uri = ContentUris.withAppendedId(mediaUri, 782 uri = ContentUris.withAppendedId(mediaUri,
906 cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media._ID))); 783 cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
@@ -916,7 +793,6 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -916,7 +793,6 @@ public class ShareMomentActivity extends AppCompatActivity {
916 } 793 }
917 if (replace.startsWith("content:")) { 794 if (replace.startsWith("content:")) {
918 String uri1 = URItoPath(replace); 795 String uri1 = URItoPath(replace);
919 - // String repl = String.valueOf(uri1).replace("file:///", "/");  
920 File file = new File(uri1); 796 File file = new File(uri1);
921 Media media = new Media(file.getPath(), file.getName(), 1, 1, file.length(), i, "", ""); 797 Media media = new Media(file.getPath(), file.getName(), 1, 1, file.length(), i, "", "");
922 medialist.add(media); 798 medialist.add(media);
@@ -947,4 +823,34 @@ public class ShareMomentActivity extends AppCompatActivity { @@ -947,4 +823,34 @@ public class ShareMomentActivity extends AppCompatActivity {
947 String img_path = actualimagecursor.getString(actual_image_column_index); 823 String img_path = actualimagecursor.getString(actual_image_column_index);
948 return img_path; 824 return img_path;
949 } 825 }
  826 +
  827 + private void killTime() {
  828 + timer.schedule(new TimerTask() {
  829 + @Override
  830 + public void run() {
  831 + finish();
  832 + }
  833 + }, 3000);
  834 + }
  835 +
  836 + private void canNotDo() {
  837 + AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享.");
  838 + killTime();
  839 + }
  840 +
  841 +
  842 + @Override
  843 + protected void onDestroy() {
  844 + super.onDestroy();
  845 + if (timer != null) timer.cancel();
  846 + }
  847 +
  848 + private String getPath(String cachePath) {
  849 + String path = (AndroidQUtil.isAndroidQ() ? this.getExternalFilesDir("") : Environment.getExternalStorageDirectory()) + cachePath;
  850 + File file = new File(path);
  851 + if (file.mkdirs()) {
  852 + return path;
  853 + }
  854 + return path;
  855 + }
950 } 856 }