|
|
@@ -1,5 +1,7 @@
|
|
|
package uas.erp.general_wms.fragment;
|
|
|
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
@@ -10,6 +12,7 @@ import android.view.KeyEvent;
|
|
|
import android.view.View;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -18,6 +21,7 @@ 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.general_wms.R;
|
|
|
import uas.erp.general_wms.global.GloableParams;
|
|
|
@@ -34,7 +38,6 @@ import uas.erp.general_wms.util.download.ProgressResponseBody;
|
|
|
import uas.erp.general_wms.view.business.CommonProgressPop;
|
|
|
|
|
|
import static uas.erp.general_wms.util.Constants.CONSTANT.APK_FILE_NAME;
|
|
|
-import static uas.erp.general_wms.util.Constants.CONSTANT.APK_FILE_PATH;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -76,13 +79,20 @@ public class VersionUpgradeFragment extends BaseFragment implements ProgressResp
|
|
|
mProgressPop.showPopupWindow();
|
|
|
|
|
|
breakPoints = 0L;
|
|
|
- File directory = new File(APK_FILE_PATH);
|
|
|
+
|
|
|
+ // 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(APK_FILE_PATH);
|
|
|
+ FileUtils.delAllFile(directory + "/general_wms/apk");
|
|
|
}
|
|
|
- file = new File(APK_FILE_PATH, APK_FILE_NAME);
|
|
|
+
|
|
|
+ // 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) {
|
|
|
@@ -99,6 +109,47 @@ public class VersionUpgradeFragment extends BaseFragment implements ProgressResp
|
|
|
protected void initDatas() {
|
|
|
mOldVersionTv.setText(AndroidUtil.getVersionName(mActivity));
|
|
|
getNewVersionMsg();
|
|
|
+
|
|
|
+ //从API 26开始需要申请安装权限
|
|
|
+ if (Build.VERSION.SDK_INT >= 26) {
|
|
|
+ if (!isHasInstallPermissionWithO(getActivity())) {
|
|
|
+ startInstallPermissionSettingActivity(getActivity());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检测是否拥有安装未知应用权限canRequestPackageInstalls
|
|
|
+ */
|
|
|
+ @RequiresApi(api = Build.VERSION_CODES.O)
|
|
|
+ private boolean isHasInstallPermissionWithO(Context context){
|
|
|
+ if (context == null){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return context.getPackageManager().canRequestPackageInstalls();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 如果没有权限,则申请安装未知应用权限(打开获取权限界面)
|
|
|
+ */
|
|
|
+ @RequiresApi(api = Build.VERSION_CODES.O)
|
|
|
+ private void startInstallPermissionSettingActivity(Context context) {
|
|
|
+ if (context == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Intent intent = new Intent();
|
|
|
+ //获取当前apk包URI,并设置到intent中(这一步设置,可让“未知应用权限设置界面”只显示当前应用的设置项)
|
|
|
+ Uri packageURI = Uri.parse("package:" + context.getPackageName());
|
|
|
+ intent.setData(packageURI);
|
|
|
+ //设置不同版本跳转未知应用的动作
|
|
|
+ if (Build.VERSION.SDK_INT >= 26) {
|
|
|
+ //intent = new Intent(android.provider.Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES,packageURI);
|
|
|
+ intent.setAction(android.provider.Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
|
|
|
+ } else {
|
|
|
+ intent.setAction(android.provider.Settings.ACTION_SECURITY_SETTINGS);
|
|
|
+ }
|
|
|
+ ((Activity) context).startActivity(intent);
|
|
|
+ Toast.makeText(getActivity(), "请打开未知应用安装权限", Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
|
|
|
private void getNewVersionMsg() {
|
|
|
@@ -182,7 +233,9 @@ public class VersionUpgradeFragment extends BaseFragment implements ProgressResp
|
|
|
CommonUtil.toastNoRepeat(mActivity, "下载完成");
|
|
|
mProgressPop.dismiss();
|
|
|
try {
|
|
|
- File apk = new File(APK_FILE_PATH, APK_FILE_NAME);
|
|
|
+ // File apk = new File(APK_FILE_PATH, APK_FILE_NAME);
|
|
|
+ String filesDir = getActivity().getFilesDir().getAbsolutePath();
|
|
|
+ File apk = new File(filesDir + "/general_wms/apk", APK_FILE_NAME);
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
|
Uri apkUri = FileProvider.getUriForFile(mActivity,
|