Commit ee6ec1d9 authored by liuzhaoce's avatar liuzhaoce

update

parent 91738477
...@@ -6,8 +6,8 @@ android { ...@@ -6,8 +6,8 @@ android {
applicationId "com.tencent.mm" applicationId "com.tencent.mm"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 26 targetSdkVersion 26
versionCode 9 versionCode 7
versionName "1.9" versionName "1.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true multiDexEnabled true
......
package top.wuhaojie.installerlibrary; package top.wuhaojie.installerlibrary;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint;
import android.app.DownloadManager; import android.app.DownloadManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
...@@ -45,9 +46,9 @@ import static top.wuhaojie.installerlibrary.AutoInstaller.Builder.parseApk; ...@@ -45,9 +46,9 @@ import static top.wuhaojie.installerlibrary.AutoInstaller.Builder.parseApk;
public class AutoInstaller extends Handler { public class AutoInstaller extends Handler {
private static final String TAG = AutoInstaller.class.getSimpleName(); private static final String TAG = AutoInstaller.class.getSimpleName();
private static final int REQUEST_CODE_PERMISSION_STORAGE = 100;
@SuppressLint("StaticFieldLeak")
private static volatile AutoInstaller mAutoInstaller; private static volatile AutoInstaller mAutoInstaller;
private Context mContext; private Context mContext;
private final String mTempPath = "sdcard/" + Environment.DIRECTORY_DOWNLOADS; private final String mTempPath = "sdcard/" + Environment.DIRECTORY_DOWNLOADS;
...@@ -131,8 +132,6 @@ public class AutoInstaller extends Handler { ...@@ -131,8 +132,6 @@ public class AutoInstaller extends Handler {
errorStream.close(); errorStream.close();
} }
} catch (IOException e) { } catch (IOException e) {
outputStream = null;
errorStream = null;
process.destroy(); process.destroy();
} }
} }
...@@ -247,9 +246,16 @@ public class AutoInstaller extends Handler { ...@@ -247,9 +246,16 @@ public class AutoInstaller extends Handler {
return false; return false;
} }
public void install(final String filePath) { private void install(final String filePath) {
if (TextUtils.isEmpty(filePath) || !filePath.endsWith(".apk")) if (TextUtils.isEmpty(filePath) || !filePath.endsWith(".apk"))
throw new IllegalArgumentException("not a correct apk file path"); throw new IllegalArgumentException("not a correct apk file path");
try {
File file = new File(filePath);
ApkMeta apkMeta = parseApk(file);
Log.e(TAG, "apk version " + apkMeta.getVersionName() + " has been downloaded.");
} catch (Exception e) {
Log.e(TAG, "apk download failed.");
}
Log.e(TAG, "filePath: " + filePath); Log.e(TAG, "filePath: " + filePath);
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
...@@ -301,17 +307,6 @@ public class AutoInstaller extends Handler { ...@@ -301,17 +307,6 @@ public class AutoInstaller extends Handler {
} }
} }
public void install(File file, String downloadUrl) {
try {
ApkMeta apkMeta = parseApk(file);
Log.e("DownLoadApp", "apk version:" + apkMeta.getVersionName() + "has been downlead");
install(file.getAbsolutePath());
} catch (Exception e) {
Log.e("DownLoadApp", "apk download failed.");
}
}
public void installFromUrl(final String httpUrl) { public void installFromUrl(final String httpUrl) {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
...@@ -413,10 +408,10 @@ public class AutoInstaller extends Handler { ...@@ -413,10 +408,10 @@ public class AutoInstaller extends Handler {
/** /**
* 通过浏览器下载APK包 * 通过浏览器下载APK包
* @param context * @param context context
* @param url * @param url url
*/ */
public static void downloadForWebView(Context context, String url) { private static void downloadForWebView(Context context, String url) {
Uri uri = Uri.parse(url); Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri); Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
...@@ -431,10 +426,12 @@ public class AutoInstaller extends Handler { ...@@ -431,10 +426,12 @@ public class AutoInstaller extends Handler {
try { try {
sslContext = SSLContext.getInstance("TLS"); sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[]{new X509TrustManager() { sslContext.init(null, new TrustManager[]{new X509TrustManager() {
@SuppressLint("TrustAllX509TrustManager")
@Override @Override
public void checkClientTrusted(X509Certificate[] chain, String authType) { public void checkClientTrusted(X509Certificate[] chain, String authType) {
} }
@SuppressLint("TrustAllX509TrustManager")
@Override @Override
public void checkServerTrusted(X509Certificate[] chain, String authType) { public void checkServerTrusted(X509Certificate[] chain, String authType) {
} }
...@@ -476,25 +473,17 @@ public class AutoInstaller extends Handler { ...@@ -476,25 +473,17 @@ public class AutoInstaller extends Handler {
return this; return this;
} }
public static ApkMeta parseApk(File file) { static ApkMeta parseApk(File file) {
//now parse the file //now parse the file
try { try {
ApkFile apkFile = new ApkFile(file); ApkFile apkFile = new ApkFile(file);
return apkFile.getApkMeta(); return apkFile.getApkMeta();
} catch (IOException e) { } catch (IOException e) {
file.delete(); resultDelete(file);
throw new IllegalStateException("the filed not a apk filed format"); throw new IllegalStateException("the filed not a apk filed format");
} }
} }
// public AutoInstaller build() {
// AutoInstaller autoInstaller = new AutoInstaller(context);
// autoInstaller.mMode = mode;
// autoInstaller.mOnStateChangedListener = onStateChangedListener;
// autoInstaller.mTempPath = directory;
// return autoInstaller;
// }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment