|
|
|
|
@ -1,11 +1,9 @@
|
|
|
|
|
package com.example.administrator.zhapp.activity;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.app.DownloadManager;
|
|
|
|
|
import android.app.Notification;
|
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
|
import android.content.ActivityNotFoundException;
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
@ -16,15 +14,12 @@ import android.content.pm.PackageManager;
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.graphics.drawable.ColorDrawable;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.Environment;
|
|
|
|
|
import android.provider.Settings;
|
|
|
|
|
import androidx.core.content.FileProvider;
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
@ -34,7 +29,8 @@ import android.widget.AdapterView;
|
|
|
|
|
import android.widget.GridView;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import com.azhon.appupdate.listener.OnButtonClickListener;
|
|
|
|
|
import com.azhon.appupdate.listener.OnDownloadListener;
|
|
|
|
|
import com.example.administrator.zhapp.DBModel.AjhScInfo;
|
|
|
|
|
import com.example.administrator.zhapp.DBModel.Ajhjh;
|
|
|
|
|
import com.example.administrator.zhapp.DBModel.Ajhxcjs;
|
|
|
|
|
@ -80,6 +76,7 @@ import com.example.administrator.zhapp.service.UploadDataService;
|
|
|
|
|
import com.example.administrator.zhapp.utils.ControllerActivity;
|
|
|
|
|
import com.example.administrator.zhapp.utils.GsonUtils;
|
|
|
|
|
import com.example.administrator.zhapp.utils.HttpListener;
|
|
|
|
|
import com.example.administrator.zhapp.utils.HttpUtils;
|
|
|
|
|
import com.example.administrator.zhapp.utils.NetworkAvailableUtils;
|
|
|
|
|
import com.example.administrator.zhapp.utils.NohttpUtils;
|
|
|
|
|
import com.example.administrator.zhapp.utils.SPUtils;
|
|
|
|
|
@ -95,6 +92,8 @@ import java.io.File;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import retrofit2.Call;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends BaseActivity {
|
|
|
|
|
|
|
|
|
|
@ -108,7 +107,6 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
private List<BasicDataBean2.DataBean> zys2;
|
|
|
|
|
private List<String> dialogDatas;
|
|
|
|
|
private List<String> dialogDatas2;
|
|
|
|
|
DownloadManager DM, mDownloadManager;
|
|
|
|
|
private long downloadId;
|
|
|
|
|
private boolean isTask = false;//是否有任务
|
|
|
|
|
private long exitTime = 0;
|
|
|
|
|
@ -219,7 +217,7 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
beanList.addAll(getGridViewData(isTask));
|
|
|
|
|
|
|
|
|
|
gv.setSelector(new ColorDrawable(Color.TRANSPARENT));
|
|
|
|
|
adapter = new GridViewAdapter(this, beanList, item, Contans.TEST);
|
|
|
|
|
adapter = new GridViewAdapter(this, beanList, item, false);
|
|
|
|
|
gv.setAdapter(adapter);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -714,43 +712,30 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
public void onSucceed(int what, Response<String> response) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ApkUpdateBean bean = GsonUtils.GsonToBean(response.get(), ApkUpdateBean.class);
|
|
|
|
|
|
|
|
|
|
if (bean != null) {
|
|
|
|
|
|
|
|
|
|
if (!bean.getTotal().equals("0")) {
|
|
|
|
|
|
|
|
|
|
final ApkUpdateBean.RowsBean versoinInfo = bean.getRows().get(0);
|
|
|
|
|
|
|
|
|
|
Log.e("Versioncode", versoinInfo.getVersioncode());
|
|
|
|
|
Log.e("Versionname", versoinInfo.getVersionname());
|
|
|
|
|
Log.e("getVersionname", getVersionName());
|
|
|
|
|
Log.e("Apkur", versoinInfo.getApkurl());
|
|
|
|
|
Log.e("Apkur2", versoinInfo.getApkurl2());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!versoinInfo.getVersionname().equals(getVersionName())) {
|
|
|
|
|
dialog = new AuditDialog(context, "发现新版本,是否更新?", new AuditDialog.AuditDialogListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void confirm() {
|
|
|
|
|
Uri uri = Uri.parse("https://www.pgyer.com/iCaX");
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void cancel() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
dialog.show();
|
|
|
|
|
String result = response.get();
|
|
|
|
|
ApkUpdateBean appUploadInfo = GsonUtils.GsonToBean(result, ApkUpdateBean.class);
|
|
|
|
|
|
|
|
|
|
if (appUploadInfo != null) {
|
|
|
|
|
if (appUploadInfo.getTotal().equals("1")) {
|
|
|
|
|
showLog(result);
|
|
|
|
|
String appURL = appUploadInfo.getRows().get(0).getApkurl();
|
|
|
|
|
String appversionname = appUploadInfo.getRows().get(0).getVersionname();
|
|
|
|
|
String versioncode = appUploadInfo.getRows().get(0).getVersioncode();
|
|
|
|
|
String appdesc = appUploadInfo.getRows().get(0).getAppdesc();
|
|
|
|
|
|
|
|
|
|
// showLog(getVersionName());
|
|
|
|
|
// showLog(appversionname);
|
|
|
|
|
// showLog(versioncode);
|
|
|
|
|
// showLog(getVersionName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!appversionname.equals(getVersionName())) {
|
|
|
|
|
if(TextUtils.isEmpty(appdesc)){
|
|
|
|
|
appdesc = "1.登录接口调整。\n2.所有接口增加token认证";
|
|
|
|
|
}
|
|
|
|
|
DownloadAndInstall(appURL, appversionname, appdesc, versioncode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
@ -766,129 +751,67 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DownloadAndInstall(String downloadURL, String versionName, String description, String versionCode) {
|
|
|
|
|
new com.azhon.appupdate.manager.DownloadManager.Builder(this)
|
|
|
|
|
.apkUrl(downloadURL)
|
|
|
|
|
.apkName("设备设施巡查.apk")
|
|
|
|
|
.smallIcon(R.mipmap.logo1)
|
|
|
|
|
.showNewerToast(false)
|
|
|
|
|
.apkVersionCode(Integer.parseInt(versionCode))
|
|
|
|
|
.apkVersionName(versionName)
|
|
|
|
|
.apkDescription(description)
|
|
|
|
|
.enableLog(true)
|
|
|
|
|
.jumpInstallPage(true)
|
|
|
|
|
.dialogButtonTextColor(Color.WHITE)
|
|
|
|
|
.dialogButtonColor(Color.parseColor("#FF8247"))
|
|
|
|
|
.dialogProgressBarColor(Color.parseColor("#FF8247"))
|
|
|
|
|
.showNotification(true)
|
|
|
|
|
.showBgdToast(true)
|
|
|
|
|
.forcedUpgrade(true)
|
|
|
|
|
.onDownloadListener(new OnDownloadListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void start() {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 下载并跳转到APK安装页面
|
|
|
|
|
*
|
|
|
|
|
* @param url
|
|
|
|
|
*/
|
|
|
|
|
private void downLoadApk(String url) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final String packageName = "com.example.administrator.zhapp";
|
|
|
|
|
int state = context.getPackageManager().getApplicationEnabledSetting(packageName);
|
|
|
|
|
//检测下载管理器是否被禁用
|
|
|
|
|
if (state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
|
|
|
|
|| state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
|
|
|
|
|
|| state == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context).setTitle("温馨提示").setMessage
|
|
|
|
|
("系统下载管理器被禁止,需手动打开").setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
|
|
|
intent.setData(Uri.parse("package:" + packageName));
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
|
Intent intent = new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
builder.create().show();
|
|
|
|
|
} else {
|
|
|
|
|
//正常下载流程
|
|
|
|
|
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
|
|
|
|
request.setAllowedOverRoaming(false);
|
|
|
|
|
|
|
|
|
|
//通知栏显示
|
|
|
|
|
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
|
|
|
|
request.setTitle("设备设施巡查");
|
|
|
|
|
request.setDescription("正在下载中...");
|
|
|
|
|
request.setVisibleInDownloadsUi(true);
|
|
|
|
|
|
|
|
|
|
//设置下载的路径
|
|
|
|
|
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "设备设施巡查.apk");
|
|
|
|
|
|
|
|
|
|
//获取DownloadManager
|
|
|
|
|
mDownloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
|
|
|
|
downloadId = mDownloadManager.enqueue(request);
|
|
|
|
|
|
|
|
|
|
context.registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void downloading(int i, int i1) {
|
|
|
|
|
|
|
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
checkStatus();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkStatus() {
|
|
|
|
|
DownloadManager.Query query = new DownloadManager.Query();
|
|
|
|
|
query.setFilterById(downloadId);
|
|
|
|
|
Cursor cursor = mDownloadManager.query(query);
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
|
@SuppressLint("Range") int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
|
|
|
|
|
switch (status) {
|
|
|
|
|
//下载暂停
|
|
|
|
|
case DownloadManager.STATUS_PAUSED:
|
|
|
|
|
break;
|
|
|
|
|
//下载延迟
|
|
|
|
|
case DownloadManager.STATUS_PENDING:
|
|
|
|
|
break;
|
|
|
|
|
//正在下载
|
|
|
|
|
case DownloadManager.STATUS_RUNNING:
|
|
|
|
|
break;
|
|
|
|
|
//下载完成
|
|
|
|
|
case DownloadManager.STATUS_SUCCESSFUL:
|
|
|
|
|
installAPK();
|
|
|
|
|
break;
|
|
|
|
|
//下载失败
|
|
|
|
|
case DownloadManager.STATUS_FAILED:
|
|
|
|
|
Toast.makeText(context, "下载失败", Toast.LENGTH_SHORT).show();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void done(@NonNull File file) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 7.0兼容
|
|
|
|
|
*/
|
|
|
|
|
private void installAPK() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
|
@Override
|
|
|
|
|
public void cancel() {
|
|
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "/com.example.administrator.zhapp/";
|
|
|
|
|
@Override
|
|
|
|
|
public void error(@NonNull Throwable throwable) {
|
|
|
|
|
|
|
|
|
|
String fileName = "设备设施巡查.apk";
|
|
|
|
|
}
|
|
|
|
|
}).onButtonClickListener(new OnButtonClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onButtonClick(int i) {
|
|
|
|
|
|
|
|
|
|
File apkFile = new File(path + fileName);
|
|
|
|
|
}
|
|
|
|
|
}).build().download();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
|
Uri apkUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", apkFile);
|
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
|
intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
|
|
|
|
|
} else {
|
|
|
|
|
intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-a rchive");
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
private String getVersionName() {
|
|
|
|
|
PackageManager pm = getPackageManager();
|
|
|
|
|
try {
|
|
|
|
|
PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0);
|
|
|
|
|
return packageInfo.versionName;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initDialogDatas() {
|
|
|
|
|
|
|
|
|
|
for (BasicDataBean.DataBean bean : zys) {
|
|
|
|
|
@ -922,19 +845,19 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getVersionName() {
|
|
|
|
|
//1,包管理者对象packageManager
|
|
|
|
|
PackageManager pm = getPackageManager();
|
|
|
|
|
//2,从包的管理者对象中,获取指定包名的基本信息(版本名称,版本号),传0代表获取基本信息
|
|
|
|
|
try {
|
|
|
|
|
PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0);
|
|
|
|
|
//3,获取版本名称
|
|
|
|
|
return packageInfo.versionName;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
// private String getVersionName() {
|
|
|
|
|
// //1,包管理者对象packageManager
|
|
|
|
|
// PackageManager pm = getPackageManager();
|
|
|
|
|
// //2,从包的管理者对象中,获取指定包名的基本信息(版本名称,版本号),传0代表获取基本信息
|
|
|
|
|
// try {
|
|
|
|
|
// PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0);
|
|
|
|
|
// //3,获取版本名称
|
|
|
|
|
// return packageInfo.versionName;
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// return null;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
|