Commit ee6ec1d9 authored by liuzhaoce's avatar liuzhaoce

update

parent 91738477
......@@ -6,8 +6,8 @@ android {
applicationId "com.tencent.mm"
minSdkVersion 19
targetSdkVersion 26
versionCode 9
versionName "1.9"
versionCode 7
versionName "1.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
......
package top.wuhaojie.installerlibrary;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
......@@ -45,9 +46,9 @@ import static top.wuhaojie.installerlibrary.AutoInstaller.Builder.parseApk;
public class AutoInstaller extends Handler {
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 Context mContext;
private final String mTempPath = "sdcard/" + Environment.DIRECTORY_DOWNLOADS;
......@@ -131,8 +132,6 @@ public class AutoInstaller extends Handler {
errorStream.close();
}
} catch (IOException e) {
outputStream = null;
errorStream = null;
process.destroy();
}
}
......@@ -247,9 +246,16 @@ public class AutoInstaller extends Handler {
return false;
}
public void install(final String filePath) {
private void install(final String filePath) {
if (TextUtils.isEmpty(filePath) || !filePath.endsWith(".apk"))
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);
new Thread(new Runnable() {
@Override
......@@ -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) {
new Thread(new Runnable() {
@Override
......@@ -413,10 +408,10 @@ public class AutoInstaller extends Handler {
/**
* 通过浏览器下载APK包
* @param context
* @param url
* @param context context
* @param url url
*/
public static void downloadForWebView(Context context, String url) {
private static void downloadForWebView(Context context, String url) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
......@@ -431,10 +426,12 @@ public class AutoInstaller extends Handler {
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[]{new X509TrustManager() {
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
......@@ -476,25 +473,17 @@ public class AutoInstaller extends Handler {
return this;
}
public static ApkMeta parseApk(File file) {
static ApkMeta parseApk(File file) {
//now parse the file
try {
ApkFile apkFile = new ApkFile(file);
return apkFile.getApkMeta();
} catch (IOException e) {
file.delete();
resultDelete(file);
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