Skip to content

Commit 88b1ce8

Browse files
committed
fix request external storage permission error on android Q
fix okhttp ssl factory error on android q
1 parent cd3389b commit 88b1ce8

File tree

8 files changed

+71
-31
lines changed

8 files changed

+71
-31
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ allprojects {
3030
task clean(type: Delete) {
3131
delete rootProject.buildDir
3232
}
33+
34+
ext{
35+
BUILD_VERSION=29
36+
}

library/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ apply plugin: 'com.github.dcendents.android-maven'
33
apply plugin: 'com.jfrog.bintray'
44
version = "2.2.3.2"
55
android {
6-
compileSdkVersion 28
7-
buildToolsVersion "28.0.3"
6+
compileSdkVersion BUILD_VERSION
87
resourcePrefix "versionchecklib"
98
defaultConfig {
109
minSdkVersion 14
11-
targetSdkVersion 28
10+
targetSdkVersion BUILD_VERSION
1211
versionCode 1
1312
versionName version
1413
}
@@ -28,7 +27,7 @@ android {
2827
dependencies {
2928
implementation fileTree(include: ['*.jar'], dir: 'libs')
3029
implementation 'com.android.support:appcompat-v7:28.0.0'
31-
implementation 'com.squareup.okhttp3:okhttp:3.8.1'
30+
implementation 'com.squareup.okhttp3:okhttp:4.3.1'
3231
implementation 'org.greenrobot:eventbus:3.1.1'
3332

3433
}

library/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<application
1414
android:allowBackup="true"
1515
android:supportsRtl="true"
16+
android:requestLegacyExternalStorage="true"
1617
android:usesCleartextTraffic="true">
1718
<activity
1819
android:name=".core.VersionDialogActivity"

library/src/main/java/com/allenliu/versionchecklib/core/http/AllenHttp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class AllenHttp {
3636
public static OkHttpClient getHttpClient() {
3737
if (client == null) {
3838
OkHttpClient.Builder builder = new OkHttpClient.Builder();
39-
builder.sslSocketFactory(createSSLSocketFactory());
39+
builder.sslSocketFactory(createSSLSocketFactory(),new TrustAllCerts());
4040
builder.connectTimeout(15,TimeUnit.SECONDS);
4141
builder.hostnameVerifier(new TrustAllHostnameVerifier());
4242
client=builder.build();
Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,68 @@
11
package com.allenliu.versionchecklib.utils;
22

3+
import android.content.Context;
34
import android.os.Environment;
5+
import android.support.annotation.NonNull;
46

57
import java.io.File;
68

9+
10+
711
public class FileHelper {
12+
@Deprecated
13+
public static String getDownloadApkCachePath() {
14+
15+
String appCachePath = null;
16+
17+
18+
if (checkSDCard()) {
19+
20+
appCachePath = Environment.getExternalStorageDirectory() + "/AllenVersionPath/";
21+
} else {
22+
appCachePath = Environment.getDataDirectory().getPath() + "/AllenVersionPath/";
23+
}
24+
File file = new File(appCachePath);
25+
if (!file.exists()) {
26+
file.mkdirs();
27+
}
28+
return appCachePath;
29+
}
830

9-
public static String getDownloadApkCachePath() {
31+
public static String getDownloadApkCachePath(Context context) {
32+
String appCachePath;
33+
if (checkSDCard()) {
34+
appCachePath = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/AllenVersionPath/";
1035

11-
String appCachePath = null;
36+
} else {
37+
appCachePath = context.getFilesDir().getAbsolutePath() + "/AllenVersionPath/";
1238

39+
}
1340

14-
if (checkSDCard()) {
15-
appCachePath = Environment.getExternalStorageDirectory() + "/AllenVersionPath/" ;
16-
} else {
17-
appCachePath = Environment.getDataDirectory().getPath() + "/AllenVersionPath/" ;
18-
}
19-
File file = new File(appCachePath);
20-
if (!file.exists()) {
21-
file.mkdirs();
22-
}
23-
return appCachePath;
24-
}
2541

42+
File file = new File(appCachePath);
43+
if (!file.exists()) {
44+
file.mkdirs();
45+
}
46+
return appCachePath;
47+
}
2648

2749

28-
/**
29-
*
30-
*/
31-
public static boolean checkSDCard() {
32-
boolean sdCardExist = Environment.getExternalStorageState().equals(
33-
Environment.MEDIA_MOUNTED);
50+
/**
51+
*
52+
*/
53+
private static boolean checkSDCard() {
3454

35-
return sdCardExist;
55+
return Environment.getExternalStorageState().equals(
56+
Environment.MEDIA_MOUNTED);
3657

37-
}
58+
}
3859

3960

61+
public static String dealDownloadPath(@NonNull String downloadAPKPath) {
62+
if (!downloadAPKPath.endsWith(File.separator)) {
63+
downloadAPKPath += File.separator;
64+
}
65+
return downloadAPKPath;
4066

67+
}
4168
}

library/src/main/java/com/allenliu/versionchecklib/v2/builder/DownloadBuilder.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public DownloadBuilder() {
5959

6060
private void initialize() {
6161
isSilentDownload = false;
62-
downloadAPKPath = FileHelper.getDownloadApkCachePath();
62+
// downloadAPKPath = FileHelper.getDownloadApkCachePath();
6363
isForceRedownload = false;
6464
isShowDownloadingDialog = true;
6565
isShowNotification = true;
@@ -321,6 +321,9 @@ public void executeMission(Context context) {
321321
e.printStackTrace();
322322
}
323323
}
324+
//fix path permission
325+
setupDownloadPath(context);
326+
// downloadAPKPath=context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getPath() + "/";
324327
if (checkWhetherNeedRequestVersion()) {
325328
RequestVersionManager.getInstance().requestVersion(this, context.getApplicationContext());
326329
} else {
@@ -329,6 +332,13 @@ public void executeMission(Context context) {
329332

330333
}
331334

335+
private void setupDownloadPath(Context context) {
336+
if (downloadAPKPath == null) {
337+
downloadAPKPath = FileHelper.getDownloadApkCachePath(context);
338+
}
339+
downloadAPKPath = FileHelper.dealDownloadPath(downloadAPKPath);
340+
}
341+
332342
public void download(Context context) {
333343
VersionService.enqueueWork(context.getApplicationContext(), this);
334344
}

library/src/main/java/com/allenliu/versionchecklib/v2/ui/VersionService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ public int onStartCommand(Intent intent, int flags, int startId) {
8787
if (!EventBus.getDefault().isRegistered(this)) {
8888
EventBus.getDefault().register(this);
8989
}
90-
9190
ALog.e("version service create");
9291
//https://issuetracker.google.com/issues/76112072
9392
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
9493
startForeground(NotificationHelper.NOTIFICATION_ID, NotificationHelper.createSimpleNotification(this));
9594
// init();
96-
return super.onStartCommand(intent, flags, startId);
95+
return START_REDELIVER_INTENT;
9796
}
9897

9998
@Override

sample/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'com.android.application'
22
//apply plugin: 'me.tatarka.retrolambda'
33
android {
4-
compileSdkVersion 28
4+
compileSdkVersion BUILD_VERSION
55
buildToolsVersion "28.0.3"
66
defaultConfig {
77
applicationId "com.allenliu.sample"
88
minSdkVersion 16
9-
targetSdkVersion 28
9+
targetSdkVersion BUILD_VERSION
1010
versionCode 1
1111
versionName "1.0"
1212

0 commit comments

Comments
 (0)