|
|
@@ -4,9 +4,11 @@ import android.annotation.SuppressLint;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.content.pm.PackageInfo;
|
|
|
import android.graphics.Color;
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
import android.graphics.drawable.GradientDrawable;
|
|
|
+import android.media.MediaMetadataRetriever;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
@@ -28,6 +30,7 @@ import com.arialyy.aria.core.download.DownloadTarget;
|
|
|
import com.arialyy.aria.core.download.DownloadTask;
|
|
|
import com.arialyy.aria.core.inf.IEntity;
|
|
|
import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
|
|
|
+import com.kfzs.duanduan.utils.ApkUtils;
|
|
|
import com.mdad.sdk.mdsdk.AdManager;
|
|
|
import com.mdad.sdk.mdsdk.common.AdData;
|
|
|
import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
@@ -65,6 +68,7 @@ import com.sheep.jiuyan.samllsheep.BuildConfig;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.FileUtil;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
@@ -82,6 +86,7 @@ import org.afinal.simplecache.ApiKey;
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
@@ -110,6 +115,7 @@ import static com.sheep.gamegroup.util.UMConfigUtils.Event.XIAOMI_GAME_RECEIVE;
|
|
|
import static com.sheep.gamegroup.util.ViewUtil.mRobTask;
|
|
|
import static com.sheep.gamegroup.view.adapter.TryMakeMoneyAdp.PUBLIC_TAG_PREFIX_TEXTVIEW_LIST;
|
|
|
import static com.sheep.gamegroup.view.adapter.WelfareAdapter.TO_REFRESH;
|
|
|
+import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;
|
|
|
|
|
|
/**
|
|
|
* 一些公用的class
|
|
|
@@ -239,7 +245,7 @@ public class CommonUtil {
|
|
|
task.setMTotalSize(Double.valueOf(size));
|
|
|
task.setMGameID(gameId);
|
|
|
task.setWhereFrom(whereFrom);
|
|
|
- task.setMApkPath(ClassFileHelper.DIR + File.separator + packageName + ClassFileHelper.FILE_SUFFIX);
|
|
|
+ task.setMApkPath(DIR + File.separator + packageName + ClassFileHelper.FILE_SUFFIX);
|
|
|
return task;
|
|
|
}
|
|
|
|
|
|
@@ -792,6 +798,28 @@ public class CommonUtil {
|
|
|
case DialogShare.ALL:
|
|
|
ViewUtil.newInstance().showShare(activity, realUrl, description);
|
|
|
return;
|
|
|
+ case DialogShare.SYS_SEND:
|
|
|
+ PackageInfo packageInfo = ApkUtils.getPackageInfo(SheepApp.getInstance().getPackageName());
|
|
|
+ if(packageInfo != null && packageInfo.applicationInfo != null && !TextUtils.isEmpty(packageInfo.applicationInfo.sourceDir)){
|
|
|
+ String dir = DIR;
|
|
|
+ //File dir = SheepApp.getInstance().getDir("apk", Context.MODE_PRIVATE);
|
|
|
+ File file = new File(dir, String.format(Locale.CHINA, "sheep_release_v%s_%d-%s.apk", packageInfo.versionName, packageInfo.versionCode, DataUtil.getInstance().getInvitationCode()));
|
|
|
+ if(!file.exists()){
|
|
|
+ try {
|
|
|
+ FileUtil.copyFile(new File(packageInfo.applicationInfo.sourceDir), file);
|
|
|
+ ZipChannelUtil.writeQUA(file, DataUtil.getInstance().getInvitationCode());
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(file.exists())
|
|
|
+ shareFile(activity, file);
|
|
|
+ else
|
|
|
+ G.showToast("暂不支持,或未打开权限");
|
|
|
+ } else {
|
|
|
+ G.showToast("暂不支持");
|
|
|
+ }
|
|
|
+ return;
|
|
|
case DialogShare.FACE_TO_FACE:
|
|
|
ViewUtil.showQR(activity, realUrl);
|
|
|
return;
|
|
|
@@ -830,7 +858,38 @@ public class CommonUtil {
|
|
|
.setCallback(new UMShareListener())
|
|
|
.share();
|
|
|
}
|
|
|
+ // 調用系統方法分享文件
|
|
|
+ public static void shareFile(Context context, File file) {
|
|
|
+ if (null != file && file.exists()) {
|
|
|
+ Intent share = new Intent(Intent.ACTION_SEND);
|
|
|
+ share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
|
|
|
+ share.setType(getMimeType(file.getAbsolutePath()));//此处可发送多种文件
|
|
|
+ share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
+ context.startActivity(Intent.createChooser(share, "分享文件"));
|
|
|
+ } else {
|
|
|
+ G.showToast("分享文件不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ // 根据文件后缀名获得对应的MIME类型。
|
|
|
+ private static String getMimeType(String filePath) {
|
|
|
+ MediaMetadataRetriever mmr = new MediaMetadataRetriever();
|
|
|
+ String mime = "*/*";
|
|
|
+ if (filePath != null) {
|
|
|
+ try {
|
|
|
+ mmr.setDataSource(filePath);
|
|
|
+ mime = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE);
|
|
|
+ } catch (IllegalStateException e) {
|
|
|
+ return mime;
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ return mime;
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ return mime;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return mime;
|
|
|
+ }
|
|
|
/**
|
|
|
* 分享
|
|
|
*
|
|
|
@@ -1807,7 +1866,7 @@ public class CommonUtil {
|
|
|
new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- File file = ViewUtil.saveImage((View) v.getParent().getParent(), ClassFileHelper.DIR, System.currentTimeMillis() + ".jpg");
|
|
|
+ File file = ViewUtil.saveImage((View) v.getParent().getParent(), DIR, System.currentTimeMillis() + ".jpg");
|
|
|
if (file != null) {
|
|
|
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
|
|
Uri uri = Uri.fromFile(file);
|
|
|
@@ -1904,7 +1963,7 @@ public class CommonUtil {
|
|
|
OkHttpUtils.get()
|
|
|
.url(url)
|
|
|
.build()
|
|
|
- .execute(new FileCallBack(ClassFileHelper.DIR, name) {
|
|
|
+ .execute(new FileCallBack(DIR, name) {
|
|
|
@Override
|
|
|
public void onError(Call call, Exception e, int id) {
|
|
|
G.showToast("下载文件失败");
|