|
@@ -1,12 +1,14 @@
|
|
|
package com.qy.agv.update;
|
|
package com.qy.agv.update;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
+import android.app.AlertDialog;
|
|
|
import android.app.AlertDialog.Builder;
|
|
import android.app.AlertDialog.Builder;
|
|
|
import android.app.Dialog;
|
|
import android.app.Dialog;
|
|
|
import android.app.Notification;
|
|
import android.app.Notification;
|
|
|
import android.app.NotificationManager;
|
|
import android.app.NotificationManager;
|
|
|
import android.app.PendingIntent;
|
|
import android.app.PendingIntent;
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
import android.content.pm.PackageManager;
|
|
import android.content.pm.PackageManager;
|
|
|
import android.content.pm.ResolveInfo;
|
|
import android.content.pm.ResolveInfo;
|
|
@@ -38,6 +40,7 @@ import org.apache.log4j.Logger;
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.MulticastSocket;
|
|
import java.net.MulticastSocket;
|
|
|
import java.net.SocketTimeoutException;
|
|
import java.net.SocketTimeoutException;
|
|
@@ -75,7 +78,7 @@ public class UpdateManager {
|
|
|
/* 更新进度条 */
|
|
/* 更新进度条 */
|
|
|
private ProgressBar mProgress;
|
|
private ProgressBar mProgress;
|
|
|
private TextView mProgressText;
|
|
private TextView mProgressText;
|
|
|
- private Dialog mDownloadDialog;
|
|
|
|
|
|
|
+ private AlertDialog mDownloadDialog;
|
|
|
private Dialog mShowDialog;
|
|
private Dialog mShowDialog;
|
|
|
public static Logger mylog =Logger.getLogger(UpdateManager.class);
|
|
public static Logger mylog =Logger.getLogger(UpdateManager.class);
|
|
|
public String next_version;
|
|
public String next_version;
|
|
@@ -142,8 +145,6 @@ public class UpdateManager {
|
|
|
if (isUpdate()) {
|
|
if (isUpdate()) {
|
|
|
if(!StringUtils.isEmpty(next_version)){
|
|
if(!StringUtils.isEmpty(next_version)){
|
|
|
ToastUtils.showToastL(mContext, "更新到版本"+next_version);
|
|
ToastUtils.showToastL(mContext, "更新到版本"+next_version);
|
|
|
- }else{
|
|
|
|
|
- ToastUtils.showToastL(mContext, "正在更新");
|
|
|
|
|
}
|
|
}
|
|
|
ProjectUtils.init();
|
|
ProjectUtils.init();
|
|
|
showDownloadDialog();
|
|
showDownloadDialog();
|
|
@@ -199,7 +200,7 @@ public class UpdateManager {
|
|
|
public void showDownloadDialog() {
|
|
public void showDownloadDialog() {
|
|
|
// 构造软件下载对话框
|
|
// 构造软件下载对话框
|
|
|
Builder builder = new Builder(mContext);
|
|
Builder builder = new Builder(mContext);
|
|
|
- builder.setTitle(R.string.soft_updating);
|
|
|
|
|
|
|
+ builder.setTitle(R.string.soft_update);
|
|
|
// 给下载对话框增加进度条
|
|
// 给下载对话框增加进度条
|
|
|
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
|
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
|
|
View v = inflater.inflate(R.layout.softupdate_progress, null);
|
|
View v = inflater.inflate(R.layout.softupdate_progress, null);
|
|
@@ -207,12 +208,21 @@ public class UpdateManager {
|
|
|
mProgressText = (TextView) v.findViewById(R.id.update_progress_text);
|
|
mProgressText = (TextView) v.findViewById(R.id.update_progress_text);
|
|
|
builder.setView(v);
|
|
builder.setView(v);
|
|
|
// 取消更新
|
|
// 取消更新
|
|
|
-// builder.setNegativeButton(R.string.soft_update_close,(dialog,which)-> dialog.dismiss());
|
|
|
|
|
|
|
+ builder.setNegativeButton(R.string.soft_update_cancel,(dialog,which)-> {
|
|
|
|
|
+ cancelUpdate = true;
|
|
|
|
|
+ dialog.dismiss();
|
|
|
|
|
+ });
|
|
|
|
|
+ builder.setPositiveButton(R.string.sure,null);
|
|
|
mDownloadDialog = builder.create();
|
|
mDownloadDialog = builder.create();
|
|
|
mDownloadDialog.setCancelable(false);
|
|
mDownloadDialog.setCancelable(false);
|
|
|
mDownloadDialog.setCanceledOnTouchOutside(false);
|
|
mDownloadDialog.setCanceledOnTouchOutside(false);
|
|
|
mDownloadDialog.show();
|
|
mDownloadDialog.show();
|
|
|
- downloadApk();
|
|
|
|
|
|
|
+ mDownloadDialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
+ public void onClick(View v){
|
|
|
|
|
+ downloadApk();
|
|
|
|
|
+ v.setVisibility(View.GONE);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -306,7 +316,7 @@ public class UpdateManager {
|
|
|
mHandler.sendMessage(msg);
|
|
mHandler.sendMessage(msg);
|
|
|
}
|
|
}
|
|
|
// 取消下载对话框显示
|
|
// 取消下载对话框显示
|
|
|
-// mDownloadDialog.dismiss();
|
|
|
|
|
|
|
+ mDownloadDialog.dismiss();
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -337,7 +347,7 @@ public class UpdateManager {
|
|
|
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
- Uri apkUri = FileProvider.getUriForFile(mContext, "com.byjr.app.fileprovider", apkfile);//在AndroidManifest中的android:authorities值
|
|
|
|
|
|
|
+ Uri apkUri = FileProvider.getUriForFile(mContext, "com.qy.agv.fileprovider", apkfile);//在AndroidManifest中的android:authorities值
|
|
|
install.setDataAndType(apkUri, "application/vnd.android.package-archive");
|
|
install.setDataAndType(apkUri, "application/vnd.android.package-archive");
|
|
|
// 查询所有符合 intent 跳转目标应用类型的应用,注意此方法必须放置在 setDataAndType 方法之后
|
|
// 查询所有符合 intent 跳转目标应用类型的应用,注意此方法必须放置在 setDataAndType 方法之后
|
|
|
List<ResolveInfo> resolveLists = mContext.getPackageManager().queryIntentActivities(install, PackageManager.MATCH_DEFAULT_ONLY);
|
|
List<ResolveInfo> resolveLists = mContext.getPackageManager().queryIntentActivities(install, PackageManager.MATCH_DEFAULT_ONLY);
|