From a7f60d5daf64c36a02fcf951821605484a40d14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Android=20=E8=BD=AE=E5=AD=90=E5=93=A5?= Date: Sun, 10 Mar 2024 12:15:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B2=A1=E6=9C=89=E5=9C=A8?= =?UTF-8?q?=E6=B8=85=E5=8D=95=E6=96=87=E4=BB=B6=E4=B8=AD=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=20foregroundServiceType=20=E5=B1=9E=E6=80=A7=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 16 ++++++++++-- common.gradle | 4 +-- library/src/main/AndroidManifest.xml | 26 +++++++++++++++++-- .../java/com/hjq/logcat/LogcatService.java | 9 +------ 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index bd4a8f0..3ec1e6e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ * 项目地址:[Github](https://github.com/getActivity/Logcat) -* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/Logcat/releases/download/11.85/Logcat.apk) +* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/Logcat/releases/download/11.86/Logcat.apk) ![](picture/demo_code.png) @@ -51,7 +51,7 @@ dependencyResolutionManagement { ```groovy dependencies { // 日志调试框架:https://github.com/getActivity/Logcat - debugImplementation 'com.github.getActivity:Logcat:11.85' + debugImplementation 'com.github.getActivity:Logcat:11.86' } ``` @@ -66,6 +66,18 @@ android.enableJetifier = true * 如果项目是基于 **Support** 包则不需要加入此配置 +#### compileSdk 版本要求 + +* 如果项目的 `compileSdkVersion` 小于 29,则需要先升级成 29 + +```groovy +android { + compileSdkVersion 29 +} +``` + +* 如果项目的 `compileSdkVersion` 大于等于 29,则不需要修改此配置 + #### 使用方式 * 无需调用,直接运行,然后授予悬浮窗权限即可 diff --git a/common.gradle b/common.gradle index d305a7a..d4af972 100644 --- a/common.gradle +++ b/common.gradle @@ -8,8 +8,8 @@ android { minSdk 16 // Android 版本适配指南:https://github.com/getActivity/AndroidVersionAdapter targetSdk 34 - versionCode 1185 - versionName "11.85" + versionCode 1186 + versionName "11.86" } // 支持 Java JDK 8 diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index f9a07d5..e97058e 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -14,7 +14,16 @@ - + + + + + @@ -31,7 +40,20 @@ android:theme="@style/Theme.AppCompat.Light.NoActionBar" android:windowSoftInputMode="stateHidden" /> - + + + + + + + diff --git a/library/src/main/java/com/hjq/logcat/LogcatService.java b/library/src/main/java/com/hjq/logcat/LogcatService.java index 269ee35..c2eb38d 100644 --- a/library/src/main/java/com/hjq/logcat/LogcatService.java +++ b/library/src/main/java/com/hjq/logcat/LogcatService.java @@ -8,9 +8,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.content.pm.ServiceInfo; import android.graphics.BitmapFactory; -import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.os.IBinder; @@ -92,12 +90,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { } // 将服务和通知绑定在一起,成为前台服务 - if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && - VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { - startForeground(BACKUP_SERVICE_NOTIFICATION_ID, builder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC); - } else { - startForeground(BACKUP_SERVICE_NOTIFICATION_ID, builder.build()); - } + startForeground(BACKUP_SERVICE_NOTIFICATION_ID, builder.build()); return super.onStartCommand(intent, flags, startId); }