|
|
@@ -5,6 +5,7 @@ import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
+import android.os.Environment;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
import android.text.TextUtils;
|
|
|
@@ -19,18 +20,15 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.android.volley.Request;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
import androidx.core.content.FileProvider;
|
|
|
import uas.erp.huiyan_wms.R;
|
|
|
-import uas.erp.huiyan_wms.application.PdaApplication;
|
|
|
import uas.erp.huiyan_wms.global.GloableParams;
|
|
|
import uas.erp.huiyan_wms.util.AndroidUtil;
|
|
|
import uas.erp.huiyan_wms.util.CommonUtil;
|
|
|
import uas.erp.huiyan_wms.util.Constants;
|
|
|
import uas.erp.huiyan_wms.util.FastjsonUtil;
|
|
|
-import uas.erp.huiyan_wms.util.FileUtils;
|
|
|
import uas.erp.huiyan_wms.util.HttpCallback;
|
|
|
import uas.erp.huiyan_wms.util.HttpParams;
|
|
|
import uas.erp.huiyan_wms.util.VolleyRequest;
|
|
|
@@ -38,8 +36,6 @@ import uas.erp.huiyan_wms.util.download.ProgressDownloader;
|
|
|
import uas.erp.huiyan_wms.util.download.ProgressResponseBody;
|
|
|
import uas.erp.huiyan_wms.view.business.CommonProgressPop;
|
|
|
|
|
|
-import static uas.erp.huiyan_wms.util.Constants.CONSTANT.APK_FILE_NAME;
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* Created by RaoMeng on 2020/4/9
|
|
|
@@ -54,6 +50,8 @@ public class VersionUpgradeFragment extends BaseFragment implements ProgressResp
|
|
|
private File file;
|
|
|
private String mAttachId;
|
|
|
|
|
|
+ private File apkFile;
|
|
|
+
|
|
|
@Override
|
|
|
protected int getLayout() {
|
|
|
return R.layout.fragment_version_upgrade;
|
|
|
@@ -81,27 +79,23 @@ public class VersionUpgradeFragment extends BaseFragment implements ProgressResp
|
|
|
|
|
|
breakPoints = 0L;
|
|
|
|
|
|
-// File directory = new File(APK_FILE_PATH);
|
|
|
- //String filesDir = getActivity().getFilesDir().getAbsolutePath();
|
|
|
- String filesDir = "/sdcard/Android/data/" + PdaApplication.getmContext().getPackageName();
|
|
|
- File directory = new File(filesDir + "/huiyan_wms/apk");
|
|
|
- if (!directory.exists() && !directory.isDirectory()) {
|
|
|
- boolean mkdirs = directory.mkdirs();
|
|
|
- } else {
|
|
|
-// FileUtils.delAllFile(APK_FILE_PATH);
|
|
|
- FileUtils.delAllFile(directory + "/huiyan_wms/apk");
|
|
|
- }
|
|
|
-
|
|
|
-// file = new File(APK_FILE_PATH, APK_FILE_NAME);
|
|
|
- file = new File(filesDir + "/huiyan_wms/apk", APK_FILE_NAME);
|
|
|
-
|
|
|
- try {
|
|
|
- file.createNewFile();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+// String filesDir = "/sdcard/Android/data/" + PdaApplication.getmContext().getPackageName();
|
|
|
+// File directory = new File(filesDir + "/huiyan_wms/apk");
|
|
|
+// if (!directory.exists() && !directory.isDirectory()) {
|
|
|
+// boolean mkdirs = directory.mkdirs();
|
|
|
+// } else {
|
|
|
+// FileUtils.delAllFile(directory + "/huiyan_wms/apk");
|
|
|
+// }
|
|
|
+// file = new File(filesDir + "/huiyan_wms/apk", APK_FILE_NAME);
|
|
|
+//
|
|
|
+// try {
|
|
|
+// file.createNewFile();
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
String downloadUrl = GloableParams.ADDRESS_COMMON_DOWNLOADBYID + "?id=" + mAttachId;
|
|
|
- mDownloader = new ProgressDownloader(downloadUrl, file, VersionUpgradeFragment.this);
|
|
|
+// mDownloader = new ProgressDownloader(downloadUrl, file, VersionUpgradeFragment.this);
|
|
|
+ mDownloader = new ProgressDownloader(downloadUrl, apkFile, VersionUpgradeFragment.this);
|
|
|
mDownloader.download(0L);
|
|
|
}
|
|
|
});
|
|
|
@@ -112,6 +106,20 @@ public class VersionUpgradeFragment extends BaseFragment implements ProgressResp
|
|
|
mOldVersionTv.setText(AndroidUtil.getVersionName(mActivity));
|
|
|
getNewVersionMsg();
|
|
|
|
|
|
+ //不同版本分区处理
|
|
|
+ File downloadDir;
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
|
+ // Android 10+ 使用私有目录
|
|
|
+ downloadDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
|
|
|
+ } else {
|
|
|
+ downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
|
|
+ }
|
|
|
+ if (!downloadDir.exists()) {
|
|
|
+ downloadDir.mkdirs();
|
|
|
+ }
|
|
|
+ String fileName = "update_" + System.currentTimeMillis() + ".apk";
|
|
|
+ apkFile = new File(downloadDir, fileName);
|
|
|
+
|
|
|
//从API 26开始需要申请安装权限
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
if (!isHasInstallPermissionWithO(getActivity())) {
|
|
|
@@ -233,20 +241,14 @@ public class VersionUpgradeFragment extends BaseFragment implements ProgressResp
|
|
|
CommonUtil.toastNoRepeat(mActivity, "下载完成");
|
|
|
mProgressPop.dismiss();
|
|
|
try {
|
|
|
-// File apk = new File(APK_FILE_PATH, APK_FILE_NAME);
|
|
|
-// String filesDir = getActivity().getFilesDir().getAbsolutePath();
|
|
|
- String filesDir = "/sdcard/Android/data/" + PdaApplication.getmContext().getPackageName();
|
|
|
- File apk = new File(filesDir + "/huiyan_wms/apk", APK_FILE_NAME);
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
|
- Uri apkUri = FileProvider.getUriForFile(mActivity,
|
|
|
- "uas.erp.huiyan_wms.fileprovider", apk);
|
|
|
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ Uri apkUri = FileProvider.getUriForFile(mActivity, getActivity().getPackageName() +".fileprovider", apkFile);
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
|
|
|
} else {
|
|
|
- intent.setDataAndType(Uri.fromFile(apk), "application/vnd.android.package-archive");
|
|
|
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
|
|
|
}
|
|
|
mActivity.startActivity(intent);
|
|
|
} catch (Exception e) {
|