|
@@ -1,20 +1,24 @@
|
|
|
package com.xwkj.sqjw.mvp.ui.fragment;
|
|
|
|
|
|
+import android.Manifest;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
-import android.content.pm.ApplicationInfo;
|
|
|
+import android.content.SharedPreferences;
|
|
|
import android.content.pm.PackageInfo;
|
|
|
import android.content.pm.PackageManager;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
+import androidx.core.app.ActivityCompat;
|
|
|
+import androidx.core.content.ContextCompat;
|
|
|
import androidx.core.content.FileProvider;
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
@@ -25,17 +29,18 @@ import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
-import android.widget.Toast;
|
|
|
|
|
|
-import com.dcloud.android.downloader.domain.DownloadInfo;
|
|
|
+import com.google.gson.Gson;
|
|
|
import com.hjq.toast.ToastUtils;
|
|
|
import com.jess.arms.base.BaseFragment;
|
|
|
import com.jess.arms.di.component.AppComponent;
|
|
|
import com.jess.arms.utils.ArmsUtils;
|
|
|
|
|
|
import com.xwkj.sqjw.BuildConfig;
|
|
|
+import com.xwkj.sqjw.app.utils.DownloadUtil;
|
|
|
import com.xwkj.sqjw.di.component.DaggerHomeComponent;
|
|
|
import com.xwkj.sqjw.mvp.contract.HomeContract;
|
|
|
+import com.xwkj.sqjw.mvp.model.api.Api;
|
|
|
import com.xwkj.sqjw.mvp.model.entity.AppEntity;
|
|
|
import com.xwkj.sqjw.mvp.presenter.HomePresenter;
|
|
|
|
|
@@ -46,6 +51,13 @@ import com.yaoxiaowen.download.DownloadConstant;
|
|
|
import com.yaoxiaowen.download.DownloadHelper;
|
|
|
import com.yaoxiaowen.download.DownloadStatus;
|
|
|
import com.yaoxiaowen.download.FileInfo;
|
|
|
+import com.zkjc.common.utils.ApkUtils;
|
|
|
+import com.zkjc.common.utils.ShareInfo;
|
|
|
+import com.zkjc.common.utils.ThirdUtils;
|
|
|
+
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
@@ -54,6 +66,11 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
+import io.dcloud.feature.sdk.DCUniMPSDK;
|
|
|
+import io.dcloud.feature.sdk.Interface.IUniMPOnCloseCallBack;
|
|
|
+import io.dcloud.feature.unimp.config.IUniMPReleaseCallBack;
|
|
|
+import io.dcloud.feature.unimp.config.UniMPOpenConfiguration;
|
|
|
+import io.dcloud.feature.unimp.config.UniMPReleaseConfiguration;
|
|
|
|
|
|
import static com.jess.arms.utils.Preconditions.checkNotNull;
|
|
|
|
|
@@ -108,15 +125,11 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon
|
|
|
list.add(new AppEntity.App());
|
|
|
}*/
|
|
|
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("current", "1");
|
|
|
- map.put("size", "10");
|
|
|
- mPresenter.getAppList(map);
|
|
|
-
|
|
|
+ checkPermission();
|
|
|
|
|
|
- PackageManager manager = getActivity().getPackageManager();
|
|
|
+ /*PackageManager manager = getActivity().getPackageManager();
|
|
|
List<ApplicationInfo> infoList = manager.getInstalledApplications(PackageManager.GET_META_DATA);
|
|
|
- /*List<AppInfo> appInfoList = new ArrayList<>();
|
|
|
+ List<AppInfo> appInfoList = new ArrayList<>();
|
|
|
for (ApplicationInfo info: infoList) {
|
|
|
AppInfo appInfo = new AppInfo();
|
|
|
appInfo.setAppId(info.packageName);
|
|
@@ -131,6 +144,58 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon
|
|
|
}*/
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("current", "1");
|
|
|
+ map.put("size", "10");
|
|
|
+ mPresenter.getAppList(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查并申请权限
|
|
|
+ */
|
|
|
+ public void checkPermission() {
|
|
|
+ int targetSdkVersion = 0;
|
|
|
+ String[] PermissionString = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
|
|
+ try {
|
|
|
+ final PackageInfo info = this.getActivity().getPackageManager().getPackageInfo(this.getActivity().getPackageName(), 0);
|
|
|
+ targetSdkVersion = info.applicationInfo.targetSdkVersion;//获取应用的Target版本
|
|
|
+ } catch (PackageManager.NameNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
+ //Build.VERSION.SDK_INT是获取当前手机版本 Build.VERSION_CODES.M为6.0系统
|
|
|
+ //如果系统>=6.0
|
|
|
+ if (targetSdkVersion >= Build.VERSION_CODES.M) {
|
|
|
+ //第 1 步: 检查是否有相应的权限
|
|
|
+ boolean isAllGranted = checkPermissionAllGranted(PermissionString);
|
|
|
+ if (isAllGranted) {
|
|
|
+ Log.e("err", "所有权限已经授权!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 一次请求多个权限, 如果其他有权限是已经授予的将会自动忽略掉
|
|
|
+ ActivityCompat.requestPermissions(getActivity(), PermissionString, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查是否拥有指定的所有权限
|
|
|
+ */
|
|
|
+ private boolean checkPermissionAllGranted(String[] permissions) {
|
|
|
+ for (String permission : permissions) {
|
|
|
+ if (ContextCompat.checkSelfPermission(getActivity(), permission) != PackageManager.PERMISSION_GRANTED) {
|
|
|
+ // 只要有一个权限没有被授予, 则直接返回 false
|
|
|
+ //Log.e("err","权限"+permission+"没有授权");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通过此方法可以使 Fragment 能够与外界做一些交互和通信, 比如说外部的 Activity 想让自己持有的某个 Fragment 对象执行一些方法,
|
|
|
* 建议在有多个需要与外界交互的方法时, 统一传 {@link Message}, 通过 what 字段来区分不同的方法, 在 {@link #setData(Object)}
|
|
@@ -206,46 +271,215 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon
|
|
|
HomeAppAdapter adapter = new HomeAppAdapter(result);
|
|
|
adapter.setListener(this);
|
|
|
recyclerView.setAdapter(adapter);
|
|
|
+ SharedPreferences sys = getActivity().getSharedPreferences("sys", Context.MODE_PRIVATE);
|
|
|
+ sys.edit().putString("appList", new Gson().toJson(result)).commit();
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onItemClick(View view, int position) {
|
|
|
+
|
|
|
AppEntity.App app = mData.get(position);
|
|
|
- switch (getPackageInfo(/*app.getPackageName()*/"com.xwkj.rhzf", /*app.getVersionCode()*/1)) {
|
|
|
- case UNINSTALL:
|
|
|
- case NEED_UPDATE:
|
|
|
-// ToastUtils.show("正在下载");
|
|
|
- download(app);
|
|
|
+ switch (app.getYyType()) {
|
|
|
+ case AppEntity.App.TYPE_APP:
|
|
|
+ switch (getPackageInfo(app.getPackageName(), app.getVersionCode())) {
|
|
|
+ case UNINSTALL:
|
|
|
+ case NEED_UPDATE:
|
|
|
+ // ToastUtils.show("正在下载");
|
|
|
+
|
|
|
+ download(app);
|
|
|
+ break;
|
|
|
+ case INSTALL:
|
|
|
+ ComponentName componetName = new ComponentName(app.getPackageName(), app.getQdlj());
|
|
|
+ try {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setComponent(componetName);
|
|
|
+ if ("com.xwkj.rhzf".equals(app.getPackageName())) {
|
|
|
+ intent.putExtra("isRhzf", true);
|
|
|
+ } else {
|
|
|
+ intent.putExtra("isRhzf", false);
|
|
|
+ }
|
|
|
+ intent.putExtra("appId", app.getId());
|
|
|
+ // sqjw
|
|
|
+ intent.putExtra("username", "sqmj1");
|
|
|
+ intent.putExtra("json", new Gson().toJson(getShareInfo()));
|
|
|
+
|
|
|
+ // jdrh
|
|
|
+ SharedPreferences sys = getActivity().getSharedPreferences("sys", Context.MODE_PRIVATE);
|
|
|
+ String userName = sys.getString("zh", "");
|
|
|
+ String password = sys.getString("mm", "");
|
|
|
+ intent.putExtra("xwkjUserName", userName);
|
|
|
+ intent.putExtra("xwkjPassword", password);
|
|
|
+ startActivity(intent);
|
|
|
+ } catch (Exception e) {
|
|
|
+ ToastUtils.show("未找到应用");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
break;
|
|
|
- case INSTALL:
|
|
|
- ComponentName componetName = new ComponentName("com.xwkj.rhzf","com.xwkj.rhzf.mvp.ui.activity.LoginActivity");
|
|
|
- try {
|
|
|
- Intent intent = new Intent();
|
|
|
- intent.setComponent(componetName);
|
|
|
- if (position == 0) {
|
|
|
- intent.putExtra("isRhzf", true);
|
|
|
- } else {
|
|
|
- intent.putExtra("isRhzf", false);
|
|
|
+ case AppEntity.App.TYPE_UNI:
|
|
|
+ DCUniMPSDK.getInstance().setUniMPOnCloseCallBack(new IUniMPOnCloseCallBack() {
|
|
|
+ @Override
|
|
|
+ public void onClose(String s) {
|
|
|
+ Log.e("eee", "onClose is run !!!!!!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ JSONObject uniApp = DCUniMPSDK.getInstance().getAppVersionInfo(app.getPackageName());
|
|
|
+ if (uniApp != null) {
|
|
|
+ try {
|
|
|
+ int code = uniApp.getInt("code");
|
|
|
+ Log.e("eee", "info ===== " + uniApp.toString());
|
|
|
+ if (app.getVersionCode() > code) {
|
|
|
+ updateWgt(app.getLink(), app.getPackageName(), app.getId());
|
|
|
+ } else {
|
|
|
+ open(app.getPackageName(), app.getId());
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- startActivity(intent);
|
|
|
- } catch (Exception e) {
|
|
|
-// ToastUtils.show("未找到应用");
|
|
|
+ } else {
|
|
|
+ Log.e("eee", "info ===== null");
|
|
|
+ updateWgt(app.getLink(), app.getPackageName(), app.getId());
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void open(String packageName, String appId) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration();
|
|
|
+// uniMPOpenConfiguration.extraData.put("darkmode", "auto");
|
|
|
+ ShareInfo shareInfo = getShareInfo();
|
|
|
+
|
|
|
+// uniMPOpenConfiguration.extraData.put("data", new Gson().toJson(shareInfo));
|
|
|
+ uniMPOpenConfiguration.extraData.put("data", new JSONObject(new Gson().toJson(shareInfo)));
|
|
|
+ uniMPOpenConfiguration.extraData.put("internet", !ApkUtils.isSqjw(getActivity()));
|
|
|
+ SharedPreferences sys = getActivity().getSharedPreferences("sys", Context.MODE_PRIVATE);
|
|
|
+ String userName = sys.getString("zh", "");
|
|
|
+ String password = sys.getString("mm", "");
|
|
|
+ uniMPOpenConfiguration.extraData.put("xwkjUserName", userName);
|
|
|
+ uniMPOpenConfiguration.extraData.put("xwkjPassword", password);
|
|
|
+ uniMPOpenConfiguration.extraData.put("appId", appId);
|
|
|
+
|
|
|
+ Log.e("eee", uniMPOpenConfiguration.extraData.toString());
|
|
|
+ DCUniMPSDK.getInstance().openUniMP(getActivity(), packageName, uniMPOpenConfiguration);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @NotNull
|
|
|
+ private ShareInfo getShareInfo() {
|
|
|
+ ShareInfo shareInfo = new ShareInfo();
|
|
|
+ shareInfo.setAppCredential("应用凭证");
|
|
|
+ shareInfo.setDataObjId("资源id");
|
|
|
+ shareInfo.setDepCode("220000000000");
|
|
|
+ shareInfo.setDepName("吉林省公安厅");
|
|
|
+ shareInfo.setMobile("13122223331");
|
|
|
+ shareInfo.setPersonCode("106470");
|
|
|
+ shareInfo.setPersonId("410000000000");
|
|
|
+ shareInfo.setPersonIdentifier("12010119610707201X");
|
|
|
+ shareInfo.setPersonName("张胜男");
|
|
|
+ shareInfo.setPersonType("10");
|
|
|
+ shareInfo.setPolice("101470");
|
|
|
+ shareInfo.setSex("男");
|
|
|
+ shareInfo.setFields("data");
|
|
|
+ shareInfo.setNetworkCode("3");
|
|
|
+ List<ShareInfo.Resource> resourceList = new ArrayList<>();
|
|
|
+ ShareInfo.Resource resource = new ShareInfo.Resource();
|
|
|
+
|
|
|
+ resource.setResourceAddress(ApkUtils.isSqjw(getActivity()) ? "http://20.3.1.162:9105/drs/ppc/v1/appQuery.do" : Api.APP_DOMAIN);
|
|
|
+ resource.setResourceRegionalismCode("220000000000");
|
|
|
+ resource.setResourceId(" 120000000000-3-0100-b0e037d83ecc4d43be788a5e9ddcbbe5");
|
|
|
+ resource.setResourceServiceType("10");
|
|
|
+ resourceList.add(resource);
|
|
|
+ shareInfo.setResourceList(resourceList);
|
|
|
+ shareInfo.setUserCredential("用户凭证");
|
|
|
+ return shareInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateWgt(String url, String name, String appId) {
|
|
|
+
|
|
|
+ ThirdUtils.getInstances().showDialog(getActivity(), "正在加载数据");
|
|
|
+ //
|
|
|
+ // final String wgtUrl = "https://native-res.dcloud.net.cn/unimp-sdk/__UNI__7AEA00D.wgt";
|
|
|
+ // final String wgtUrl = "https://native-res.dcloud.net.cn/unimp-sdk/__UNI__7AEA00D.wgt";
|
|
|
+ final String wgtUrl = url;
|
|
|
+ final String wgtName = name + ".wgt";
|
|
|
+
|
|
|
+ String downFilePath = getActivity().getExternalCacheDir().getPath();
|
|
|
+
|
|
|
+ Handler uiHandler = new Handler();
|
|
|
+ JSONObject uniApp = DCUniMPSDK.getInstance().getAppVersionInfo(name);
|
|
|
+ if (uniApp != null) {
|
|
|
+ Log.e("eee", "info ===== " + uniApp.toString());
|
|
|
+ }
|
|
|
+ DownloadUtil.get().download(getActivity(), wgtUrl, downFilePath, wgtName, new DownloadUtil.OnDownloadListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDownloadSuccess(File file) {
|
|
|
+
|
|
|
+ ThirdUtils.getInstances().dismissDialog();
|
|
|
+
|
|
|
+ UniMPReleaseConfiguration uniMPReleaseConfiguration = new UniMPReleaseConfiguration();
|
|
|
+ uniMPReleaseConfiguration.wgtPath = file.getPath();
|
|
|
+ uniMPReleaseConfiguration.password = "789456123";
|
|
|
+
|
|
|
+ uiHandler.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ DCUniMPSDK.getInstance().releaseWgtToRunPath(name, uniMPReleaseConfiguration, new IUniMPReleaseCallBack() {
|
|
|
+ @Override
|
|
|
+ public void onCallBack(int code, Object pArgs) {
|
|
|
+ if (code == 1) {
|
|
|
+ //释放wgt完成
|
|
|
+
|
|
|
+ try {
|
|
|
+ open(name, appId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //释放wgt失败
|
|
|
+ Log.e("eee", "code ======= " + code);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDownloading(int progress) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDownloadFailed() {
|
|
|
+ Log.e("unimp", "downFilePath === onDownloadFailed");
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void download(AppEntity.App app) {
|
|
|
+
|
|
|
+ ThirdUtils.getInstances().showDialog(getActivity(), "正在加载数据");
|
|
|
String ACTION = app.getPackageName();
|
|
|
- File apkFile = new File(getDir(), /*app.getName() + */"test.apk");
|
|
|
+ File apkFile = new File(getDir(), app.getName() + ".apk");
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
filter.addAction(ACTION);
|
|
|
getActivity().registerReceiver(receiver, filter);
|
|
|
DownloadHelper helper = DownloadHelper.getInstance();
|
|
|
- helper.addTask("http://118.195.196.59:9000/jdrh/upload/20240704/2fe3c1a6992b109e20efdc991fd9a2cf.apk", apkFile, ACTION).submit(getActivity());
|
|
|
+ helper.addTask(app.getLink().replace("10.106.38.18:9000", "192.168.20.228:7022/downloadApk/"), apkFile, ACTION).submit(getActivity());
|
|
|
}
|
|
|
private File getDir(){
|
|
|
if (dir!=null && dir.exists()){
|
|
@@ -267,14 +501,14 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon
|
|
|
PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(pkgName, 0);
|
|
|
int versionCode = packageInfo.versionCode;
|
|
|
if (version > versionCode) {
|
|
|
- return 2;
|
|
|
+ return NEED_UPDATE;
|
|
|
}
|
|
|
Log.e("eee", "版本号:" + versionCode);
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
|
e.printStackTrace();
|
|
|
return UNINSTALL;
|
|
|
}
|
|
|
- return 1;
|
|
|
+ return INSTALL;
|
|
|
}
|
|
|
@Override
|
|
|
public boolean onItemLongClick(View view, int position) {
|
|
@@ -293,6 +527,8 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon
|
|
|
|
|
|
// progressBar.setProgress(progress);
|
|
|
if (firstFileInfo.getDownloadStatus() == DownloadStatus.COMPLETE) {
|
|
|
+
|
|
|
+ ThirdUtils.getInstances().dismissDialog();
|
|
|
File file = new File(firstFileInfo.getFilePath());
|
|
|
|
|
|
|