|
|
@@ -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,7 +20,6 @@ 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;
|
|
|
@@ -29,7 +29,6 @@ import uas.erp.general_wms.util.AndroidUtil;
|
|
|
import uas.erp.general_wms.util.CommonUtil;
|
|
|
import uas.erp.general_wms.util.Constants;
|
|
|
import uas.erp.general_wms.util.FastjsonUtil;
|
|
|
-import uas.erp.general_wms.util.FileUtils;
|
|
|
import uas.erp.general_wms.util.HttpCallback;
|
|
|
import uas.erp.general_wms.util.HttpParams;
|
|
|
import uas.erp.general_wms.util.VolleyRequest;
|
|
|
@@ -53,6 +52,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;
|
|
|
@@ -80,26 +81,8 @@ public class VersionUpgradeFragment extends BaseFragment implements ProgressResp
|
|
|
|
|
|
breakPoints = 0L;
|
|
|
|
|
|
- // File directory = new File(APK_FILE_PATH);
|
|
|
- String filesDir = getActivity().getFilesDir().getAbsolutePath();
|
|
|
- File directory = new File(filesDir + "/general_wms/apk");
|
|
|
- if (!directory.exists() && !directory.isDirectory()) {
|
|
|
- boolean mkdirs = directory.mkdirs();
|
|
|
- } else {
|
|
|
- // FileUtils.delAllFile(APK_FILE_PATH);
|
|
|
- FileUtils.delAllFile(directory + "/general_wms/apk");
|
|
|
- }
|
|
|
-
|
|
|
- // file = new File(APK_FILE_PATH, APK_FILE_NAME);
|
|
|
- file = new File(filesDir + "/general_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, apkFile, VersionUpgradeFragment.this);
|
|
|
mDownloader.download(0L);
|
|
|
}
|
|
|
});
|
|
|
@@ -109,6 +92,19 @@ public class VersionUpgradeFragment extends BaseFragment implements ProgressResp
|
|
|
protected void initDatas() {
|
|
|
mOldVersionTv.setText(AndroidUtil.getVersionName(mActivity));
|
|
|
getNewVersionMsg();
|
|
|
+ //不同版本分区处理
|
|
|
+ File downloadDir;
|
|
|
+ if (Build.VERSION.SDK_INT >= 29) {
|
|
|
+ // 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) {
|