Commit 1a8cd127fc726fb3bc4a3881dc2a9a9bf3d47b2a

Authored by 袁思汶
1 parent 05b88d37

fourth

OutSide_Share/src/main/java/com/cnlive/outside_share/activity/ShareMomentActivity.java
1 1 package com.cnlive.outside_share.activity;
2 2  
3   -import android.app.Activity;
4 3 import android.content.ContentUris;
5 4 import android.content.Context;
6 5 import android.content.Intent;
7 6 import android.content.SharedPreferences;
8   -import android.content.pm.PackageManager;
9   -import android.content.pm.ResolveInfo;
10 7 import android.database.Cursor;
11   -import android.graphics.Bitmap;
12 8 import android.media.MediaPlayer;
13 9 import android.net.Uri;
14 10 import android.os.Build;
... ... @@ -16,7 +12,6 @@ import android.os.Bundle;
16 12 import android.os.Environment;
17 13 import android.provider.DocumentsContract;
18 14 import android.provider.MediaStore;
19   -import android.provider.Settings;
20 15 import android.text.TextUtils;
21 16 import android.util.Log;
22 17  
... ... @@ -31,7 +26,6 @@ import com.cnlive.libs.base.util.ShareReleaseInfoUtil;
31 26 import com.cnlive.libs.base.util.StringUtils;
32 27 import com.cnlive.media.picker.entity.Media;
33 28 import com.cnlive.media.picker.utils.AndroidQUtil;
34   -import com.cnlive.media.picker.utils.BrandUtils;
35 29 import com.cnlive.outside_share.R;
36 30 import com.cnlive.outside_share.util.FileType;
37 31 import com.cnlive.outside_share.util.FileUtil;
... ... @@ -67,70 +61,35 @@ import androidx.appcompat.app.AppCompatActivity;
67 61 @Route(path = "/out/ShareMomentActivity")
68 62 public class ShareMomentActivity extends AppCompatActivity {
69 63  
70   -
71 64 private File filevideo;
72   - private String textUri = "";
73   - private String text = "";
74   - private String screenShot = "";
75   - private String subject = "";
76 65 private SharedPreferences preferences;
77 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 68 private Bundle bundle;
85 69 private String TEXT = "android.intent.extra.TEXT";
86 70 private String SUBJECT = "android.intent.extra.SUBJECT";
87 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 75 @RequiresApi(api = Build.VERSION_CODES.KITKAT)
102 76 @Override
103 77 protected void onCreate(@Nullable Bundle savedInstanceState) {
104 78 super.onCreate(savedInstanceState);
105 79 setContentView(R.layout.sharemoment);
106   - AlertUtil.showDeftToast(this,"进入页面");
  80 + AlertUtil.showDeftToast(this, "进入页面"); // todo Delete
107 81 timer = new Timer();
108 82 type = getIntent().getStringExtra("type");
109 83 bundle = getIntent().getBundleExtra("bundle");
110 84 action = getIntent().getStringExtra("action");
111 85 mutil = getIntent().getStringArrayListExtra("mutil");
112 86 outTyp = getIntent().getStringExtra("outType");
113   -
114 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 90 @RequiresApi(api = Build.VERSION_CODES.KITKAT)
133 91 public void checkIntent() {
  92 + equals = "shareMom".equals(outTyp); ////是否二次登陆 以下所有type均需要判断是否二次登录
134 93 if (bundle != null && action != null) {
135 94 switch (action) {
136 95 case Intent.ACTION_SEND:
... ... @@ -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 111 File filelogo = new File(getPath("/strike/cache/") + "sharefirst.jpg");
163   - preferences = this.getSharedPreferences("OutShare", MODE_PRIVATE);
164   -
165 112 if (!filelogo.exists()) {
166 113 new Thread() {
167 114 @Override
... ... @@ -182,31 +129,29 @@ public class ShareMomentActivity extends AppCompatActivity {
182 129 AlertUtil.showDeftToast(this, "数据获取异常,暂不支持此机型分享.");
183 130 killTime();
184 131 } else if (type.startsWith("text/")) {
185   - //case "text/plain":
186 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 134 if (textUri == null || TextUtils.isEmpty(textUri.toString())) {
190   - if ("shareMom".equals(outTyp)) {
  135 + if (equals) {
191 136 link = preferences.getString("extratext", "");
192 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 145 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
201 146 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
202 147 shareConfig.setImage(AppConfig.getShareLink());
203 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 150 shareConfig.setUrl(link);
206 151 shareConfig.shareRelease(this);
207 152 finish();
208 153 } else {
209   - if (link.contains("mp.weixin.qq.com")) {
  154 + if (link.contains("mp.weixin.qq.com")) { //微信公众号类型链接
210 155 new Thread(new Runnable() {
211 156 @Override
212 157 public void run() {
... ... @@ -215,55 +160,53 @@ public class ShareMomentActivity extends AppCompatActivity {
215 160 Document document = null;
216 161 try {
217 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 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 196 }).start();
252   - } else {
253   - if (("shareMom".equals(outTyp))) {
  197 + } else { //普通连接类型
  198 + if (equals) { //二次登录
254 199 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
255 200 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
256 201 shareConfig.setImage(AppConfig.getShareLink());
257 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 204 shareConfig.setUrl(link);
260 205 shareConfig.shareRelease(context);
261 206 finish();
262   - } else {
  207 + } else { //首次登录
263 208 try {
264   - //授权Uri的读取权限
265   - //若不授权,在 Android 6.0 以上测试崩溃
266   - //第一个参数为需要授权的apk包名
  209 + //授权Uri的读取权限 若不授权,在 Android 6.0 以上测试崩溃 第一个参数为需要授权的apk包名
267 210 grantUriPermission("com.cnlive.strike", screenShot, Intent.FLAG_GRANT_READ_URI_PERMISSION);
268 211 //通过 Uri 获取截屏图片的输入流
269 212 InputStream is = getContentResolver().openInputStream(screenShot);
... ... @@ -283,26 +226,26 @@ public class ShareMomentActivity extends AppCompatActivity {
283 226 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
284 227 shareConfig.setImage(AppConfig.getShareLink());
285 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 230 shareConfig.setUrl(link);
288 231 shareConfig.shareRelease(context);
289 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 237 jumpReleaseActivity(context, new ArrayList<Media>(), 3, link, "nocircle");
295 238 finish();
296   - } else if (link.contains("http") && !link.startsWith("http")) {
  239 + } else if (link.contains("http") && !link.startsWith("http")) { //带文字实体前缀的复合类型链接
297 240 String linkcontext = link.replaceAll("\\s*", "");
298   - int end;
  241 + int end; //截取前缀文字作为分享标题内容 ,后半段为链接link内容
299 242 int begin = linkcontext.indexOf("http");
300 243 if (linkcontext.contains("(")) {
301 244 end = linkcontext.indexOf("(");
302 245 } else {
303 246 end = linkcontext.length();
304 247 }
305   - String file = getIntent().getExtras().getString("file");
  248 + String file = bundle.getString("file");
306 249 FileUtil.copyFile(file, getPath("/strike/cache/") + "share.jpg");
307 250 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
308 251 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
... ... @@ -315,37 +258,37 @@ public class ShareMomentActivity extends AppCompatActivity {
315 258 Document document = null;
316 259 try {
317 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 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 293 }).start();
351 294 } else {
... ... @@ -357,25 +300,22 @@ public class ShareMomentActivity extends AppCompatActivity {
357 300 finish();
358 301 }
359 302 } else {
360   - AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享.");
361   - killTime();
  303 + canNotDo();
362 304 }
363 305 } else {
364   - AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享.");
365   - killTime();
  306 + canNotDo();
366 307 }
367 308 } else {
368   - AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享");
369   - killTime();
  309 + canNotDo();
370 310 }
371 311 } else if (type.startsWith("image/")) {
372 312 //兼容QQ浏览器链接类型
373 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 319 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
380 320 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
381 321 shareConfig.setImage(AppConfig.getShareLink());
... ... @@ -385,10 +325,10 @@ public class ShareMomentActivity extends AppCompatActivity {
385 325 shareConfig.shareRelease(context);
386 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 332 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
393 333 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
394 334 shareConfig.setImage(weixin_img_url);
... ... @@ -398,7 +338,7 @@ public class ShareMomentActivity extends AppCompatActivity {
398 338 shareConfig.shareRelease(context);
399 339 finish();
400 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 342 if ("image/gif".equals(type) || "image/vnd.wap.wbmp".equals(type) || imageUri == null) {
403 343 if (DoublePressed.onDoublePressed()) return;
404 344 AlertUtil.showDeftToast(context, "网家家暂不支持此格式图片分享.");
... ... @@ -407,10 +347,10 @@ public class ShareMomentActivity extends AppCompatActivity {
407 347 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, imageUri));
408 348 String pathreal = getPath(context, imageUri);
409 349 String fileType = FileType.getFileType(pathreal);
410   - if ("wbmp".equals(fileType)) {
  350 + if ("wbmp".equals(fileType) || pathreal == null) {
411 351 AlertUtil.showDeftToast(context, "网家家暂不支持此格式图片分享.");
412 352 killTime();
413   - } else if ("video".equals(fileType) || "avi".equals(fileType)) {
  353 + } else if ("video".equals(fileType) || "avi".equals(fileType)) { //兼容部分浏览器视频类型文件以图片type封装intent传递
414 354 filevideo = new File(pathreal); //pic 1 video 3
415 355 MediaPlayer mediaPlayer = new MediaPlayer();
416 356 try {
... ... @@ -430,19 +370,17 @@ public class ShareMomentActivity extends AppCompatActivity {
430 370 jumpReleaseActivity(context, medialist, 3, "", "nocircle");
431 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 375 ArrayList<Media> medialist = new ArrayList<>();
436 376 Media media = new Media(file.getPath(), file.getName(), 1, 1, file.length(), 0, "", "");
437 377 medialist.add(media);
438 378 jumpReleaseActivity(context, medialist, 3, "", "nocircle");
439 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 381 bundle.get(TEXT) != null && !(bundle.get(TEXT) + "").contains("http")) { //腾讯文件Android Q
442 382 String pathImg = getPath(context, imageUri);
443 383 Uri mediaUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
444   -
445   -
446 384 String[] projection = {MediaStore.Images.Media._ID,
447 385 MediaStore.Images.Media.DATA,
448 386 MediaStore.Images.Media.DATE_ADDED,
... ... @@ -453,7 +391,6 @@ public class ShareMomentActivity extends AppCompatActivity {
453 391 MediaStore.Images.Media.DISPLAY_NAME + "= ?",
454 392 new String[]{pathImg.substring(pathImg.lastIndexOf("/") + 1)},
455 393 null);
456   -
457 394 Uri uri = null;
458 395 if (cursor != null && cursor.moveToFirst()) {
459 396 uri = ContentUris.withAppendedId(mediaUri,
... ... @@ -464,15 +401,13 @@ public class ShareMomentActivity extends AppCompatActivity {
464 401 killTime();
465 402 }
466 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 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 407 if (link.contains("http") && !link.startsWith("http")) {
471 408 int begin = link.indexOf("http");
472 409 int end = link.length();
473   - // if (imageUri.toString().contains("QQBrowser") && imageUri.toString().endsWith(".png")) {
474 410 FileUtil.copyFile(imageUri.toString(), getPath("/strike/cache/") + "share.jpg");
475   - // }
476 411 ShareReleaseInfoUtil.ShareConfig shareConfig = ShareReleaseInfoUtil.ShareConfig.newInstance();
477 412 shareConfig.setType(ShareReleaseInfoUtil.TYPE_HTML);
478 413 shareConfig.setImage(AppConfig.getShareLink());
... ... @@ -482,11 +417,8 @@ public class ShareMomentActivity extends AppCompatActivity {
482 417 shareConfig.shareRelease(context);
483 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 422 String chromePath = preferences.getString("chromePath", "");
491 423 String chromeName = preferences.getString("chromeName", "");
492 424 long chromeLength = preferences.getLong("chromeLength", 10);
... ... @@ -501,10 +433,9 @@ public class ShareMomentActivity extends AppCompatActivity {
501 433 } else {
502 434 String pathImg = getPath(context, imageUri);
503 435 if (pathImg == null && !imageUri.toString().contains("QQBrowser") && !imageUri.toString().endsWith(".png")) {
504   - AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享.");
505   - killTime();
  436 + canNotDo();
506 437 } else {
507   - if (pathImg != null && pathImg.endsWith("wbmp")) {
  438 + if (pathImg == null || pathImg.endsWith("wbmp")) {
508 439 AlertUtil.showDeftToast(this, "网家家暂不支持此格式图片分享.");
509 440 killTime();
510 441 } else {
... ... @@ -519,20 +450,15 @@ public class ShareMomentActivity extends AppCompatActivity {
519 450 }
520 451 }
521 452 }
522   -
523 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 455 if (videoUri == null) {
526   - AlertUtil.showDeftToast(this, "网家家暂不支持此类型信息分享.");
527   - killTime();
  456 + canNotDo();
528 457 } else {
529 458 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, videoUri));
530 459 if ((videoUri + "").contains("file://")) {
531   -
532 460 String pathImg = getPath(context, videoUri);
533 461 Uri mediaUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
534   -
535   -
536 462 String[] projection = {MediaStore.Video.Media._ID,
537 463 MediaStore.Video.Media.DATA,
538 464 MediaStore.Video.Media.DATE_ADDED,
... ... @@ -543,8 +469,6 @@ public class ShareMomentActivity extends AppCompatActivity {
543 469 MediaStore.Video.Media.DISPLAY_NAME + "= ?",
544 470 new String[]{pathImg.substring(pathImg.lastIndexOf("/") + 1)},
545 471 null);
546   -
547   - //Uri uriQ = null;
548 472 if (cursor != null && cursor.moveToFirst()) {
549 473 videoUri = ContentUris.withAppendedId(mediaUri,
550 474 cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID)));
... ... @@ -594,17 +518,13 @@ public class ShareMomentActivity extends AppCompatActivity {
594 518  
595 519 private void startUriAddress(Context context, Uri imageUri) {
596 520 String path = imageUri.getPath();
597   - Bitmap bitmap;
598 521 InputStream is = null;
599 522 String md5 = null;
600 523 int byteread = 0;
601 524 String extension;
602   -
603 525 try {
604 526 context.grantUriPermission(AppConfig.getAppPackeg(), imageUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
605 527 is = context.getContentResolver().openInputStream(imageUri);
606   -
607   - //---
608 528 ByteArrayOutputStream baos = new ByteArrayOutputStream();
609 529 byte[] buffer = new byte[1024];
610 530 int len;
... ... @@ -614,22 +534,15 @@ public class ShareMomentActivity extends AppCompatActivity {
614 534 is.close();
615 535 baos.flush();
616 536 baos.close();
617   -
618 537 InputStream stream1 = new ByteArrayInputStream(baos.toByteArray());
619 538 InputStream stream2 = new ByteArrayInputStream(baos.toByteArray());
620   - //---
621   -
622   -
623 539 md5 = MD5Util.getMD5(stream1);
624 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 542 if (!appDir.exists()) appDir.mkdir();
629 543  
630 544 extension = FileUtil.getExtensionName(path);
631 545 extension = TextUtils.isEmpty(extension) ? "" : ("." + extension);
632   -
633 546 File file = new File(appDir, md5 + extension);
634 547  
635 548 FileOutputStream fs = new FileOutputStream(file);
... ... @@ -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 568 public static String getFilePathFromURI(Context context, Uri contentUri) {
676 569 String fileName = getFileName(contentUri);
677 570 if (!TextUtils.isEmpty(fileName)) {
... ... @@ -759,26 +652,18 @@ public class ShareMomentActivity extends AppCompatActivity {
759 652  
760 653 @RequiresApi(api = Build.VERSION_CODES.KITKAT)
761 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 656 if (isExternalStorageDocument(uri)) {
769 657 final String docId = DocumentsContract.getDocumentId(uri);
770 658 final String[] split = docId.split(":");
771 659 final String type = split[0];
772   -
773 660 if ("primary".equalsIgnoreCase(type)) {
774 661 return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ? context.getExternalFilesDir("") : Environment.getExternalStorageDirectory()) + "/" + split[1];
775 662 }
776 663 } else if (isDownloadsDocument(uri)) {
777   -
778 664 final String id = DocumentsContract.getDocumentId(uri);
779 665 final Uri contentUri = ContentUris.withAppendedId(
780 666 Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
781   -
782 667 return getDataColumn(context, contentUri, null, null);
783 668 }
784 669 // MediaProvider
... ... @@ -806,7 +691,6 @@ public class ShareMomentActivity extends AppCompatActivity {
806 691 }
807 692 // MediaStore (and general)
808 693 else if (uri != null && uri.getScheme() != null && "content".equalsIgnoreCase(uri.getScheme())) {
809   -
810 694 // Return the remote address
811 695 if (isGooglePhotosUri(uri))
812 696 return uri.getLastPathSegment();
... ... @@ -817,7 +701,6 @@ public class ShareMomentActivity extends AppCompatActivity {
817 701 else if (uri != null && uri.getScheme() != null && "file".equalsIgnoreCase(uri.getScheme())) {
818 702 return uri.getPath();
819 703 }
820   -
821 704 return null;
822 705 }
823 706  
... ... @@ -840,7 +723,6 @@ public class ShareMomentActivity extends AppCompatActivity {
840 723  
841 724 public static String getDataColumn(Context context, Uri uri, String selection,
842 725 String[] selectionArgs) {
843   -
844 726 Cursor cursor = null;
845 727 final String column = "_data";
846 728 final String[] projection = {column};
... ... @@ -853,7 +735,7 @@ public class ShareMomentActivity extends AppCompatActivity {
853 735 return cursor.getString(index);
854 736 }
855 737 } catch (Exception e) {
856   - Log.e("data主键找不到", e.getMessage());
  738 + Log.e("data主键找不到", e.getMessage() + "没有主键");
857 739 } finally {
858 740 if (cursor != null)
859 741 cursor.close();
... ... @@ -869,7 +751,7 @@ public class ShareMomentActivity extends AppCompatActivity {
869 751 killTime();
870 752 } else {
871 753 if (type.startsWith("image/")) {
872   - if ("shareMom".equals(outTyp)) {
  754 + if (equals) {
873 755 String clipDataImg = preferences.getString("clipDataImg", "");
874 756 Gson gson = new Gson();
875 757 Type listType = new TypeToken<List<Media>>() {
... ... @@ -884,11 +766,8 @@ public class ShareMomentActivity extends AppCompatActivity {
884 766  
885 767 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));
886 768 if ((uri + "").contains("file://")) {
887   -
888 769 String pathImg = getPath(context, uri);
889 770 Uri mediaUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
890   -
891   -
892 771 String[] projection = {MediaStore.Images.Media._ID,
893 772 MediaStore.Images.Media.DATA,
894 773 MediaStore.Images.Media.DATE_ADDED,
... ... @@ -899,8 +778,6 @@ public class ShareMomentActivity extends AppCompatActivity {
899 778 MediaStore.Images.Media.DISPLAY_NAME + "= ?",
900 779 new String[]{pathImg.substring(pathImg.lastIndexOf("/") + 1)},
901 780 null);
902   -
903   - //Uri uriQ = null;
904 781 if (cursor != null && cursor.moveToFirst()) {
905 782 uri = ContentUris.withAppendedId(mediaUri,
906 783 cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
... ... @@ -916,7 +793,6 @@ public class ShareMomentActivity extends AppCompatActivity {
916 793 }
917 794 if (replace.startsWith("content:")) {
918 795 String uri1 = URItoPath(replace);
919   - // String repl = String.valueOf(uri1).replace("file:///", "/");
920 796 File file = new File(uri1);
921 797 Media media = new Media(file.getPath(), file.getName(), 1, 1, file.length(), i, "", "");
922 798 medialist.add(media);
... ... @@ -947,4 +823,34 @@ public class ShareMomentActivity extends AppCompatActivity {
947 823 String img_path = actualimagecursor.getString(actual_image_column_index);
948 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 }
... ...