Skip to content

Commit 07a9291

Browse files
committed
兼容低版本的 targetSdkVersion 应用集成
1 parent c7b92f3 commit 07a9291

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

Logcat.apk

1.03 MB
Binary file not shown.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
```groovy
1212
dependencies {
13-
debugImplementation 'com.hjq:logcat:8.6'
13+
debugImplementation 'com.hjq:logcat:8.8'
1414
}
1515
```
1616

@@ -71,7 +71,7 @@ dependencies {
7171

7272
#### 作者的其他开源项目
7373

74-
* 安卓架构[AndroidProject](https://github.com/getActivity/AndroidProject)
74+
* 安卓技术中台[AndroidProject](https://github.com/getActivity/AndroidProject)
7575

7676
* 网络框架:[EasyHttp](https://github.com/getActivity/EasyHttp)
7777

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.hjq.logcat.demo"
88
minSdkVersion 14
99
targetSdkVersion 30
10-
versionCode 86
11-
versionName "8.6"
10+
versionCode 88
11+
versionName "8.8"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313
}
1414
buildTypes {

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
android:icon="@mipmap/ic_launcher"
1212
android:label="@string/app_name"
1313
android:networkSecurityConfig="@xml/network_security_config"
14+
android:requestLegacyExternalStorage="true"
1415
android:theme="@style/AppTheme"
15-
tools:targetApi="n">
16+
tools:targetApi="q">
1617

1718
<activity
1819
android:name=".MainActivity"

library/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ android {
99

1010
defaultConfig {
1111
minSdkVersion 14
12-
targetSdkVersion 30
13-
versionCode 86
14-
versionName "8.6"
12+
targetSdkVersion 26
13+
versionCode 88
14+
versionName "8.8"
1515
}
1616
}
1717

@@ -26,7 +26,7 @@ publish {
2626
userOrg = 'getactivity'
2727
groupId = 'com.hjq'
2828
artifactId = 'logcat'
29-
version = '8.6'
29+
version = '8.8'
3030
description = 'This is to help developers quickly see the logging framework they want'
3131
website = "https://github.com/getActivity/Logcat"
3232
}

library/src/main/java/com/hjq/logcat/LogcatActivity.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void onSelected(final int location) {
179179
break;
180180
case 3:
181181
XXPermissions.with(LogcatActivity.this)
182-
.permission(Permission.MANAGE_EXTERNAL_STORAGE)
182+
.permission(getStoragePermission())
183183
.request(new OnPermission() {
184184
@Override
185185
public void hasPermission(List<String> granted, boolean all) {
@@ -226,7 +226,7 @@ public boolean onLongClick(View v) {
226226
public void onClick(View v) {
227227
if (v == mSaveView) {
228228
XXPermissions.with(this)
229-
.permission(Permission.MANAGE_EXTERNAL_STORAGE)
229+
.permission(getStoragePermission())
230230
.request(new OnPermission() {
231231
@Override
232232
public void hasPermission(List<String> granted, boolean all) {
@@ -389,7 +389,7 @@ public void run() {
389389
*/
390390
private void initFilter() {
391391
File file = new File(LOG_DIRECTORY, LOGCAT_TAG_FILTER_FILE);
392-
if (file.exists() && file.isFile() && XXPermissions.hasPermission(this, Permission.MANAGE_EXTERNAL_STORAGE)) {
392+
if (file.exists() && file.isFile() && XXPermissions.hasPermission(this, getStoragePermission())) {
393393
BufferedReader reader = null;
394394
try {
395395
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),
@@ -533,4 +533,18 @@ protected void onDestroy() {
533533
super.onDestroy();
534534
LogcatManager.destroy();
535535
}
536+
537+
/**
538+
* 获取存储权限
539+
*/
540+
private String[] getStoragePermission() {
541+
// 如果当前应用适配的是 Android 11 及以上
542+
if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R) {
543+
// 返回 Android 11 的存储权限
544+
return new String[]{Permission.MANAGE_EXTERNAL_STORAGE};
545+
} else {
546+
// 否则就返回旧版的存储权限
547+
return Permission.Group.STORAGE;
548+
}
549+
}
536550
}

0 commit comments

Comments
 (0)