Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
G
g4proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
g4proxy
Commits
ee6ec1d9
Commit
ee6ec1d9
authored
May 16, 2019
by
liuzhaoce
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
91738477
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
30 deletions
+19
-30
build.gradle
app/build.gradle
+2
-2
AutoInstaller.java
...ain/java/top/wuhaojie/installerlibrary/AutoInstaller.java
+17
-28
No files found.
app/build.gradle
View file @
ee6ec1d9
...
...
@@ -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
...
...
app/src/main/java/top/wuhaojie/installerlibrary/AutoInstaller.java
View file @
ee6ec1d9
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
;
}
p
ublic
void
install
(
final
String
filePath
)
{
p
rivate
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
*/
p
ublic
static
void
downloadForWebView
(
Context
context
,
String
url
)
{
p
rivate
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;
// }
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment