diff --git a/README.md b/README.md
index b261fca..e8798a1 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.6/Logcat.apk)
+* 可以扫码下载 Demo 进行演示或者测试,如果扫码下载不了的,[点击此处可直接下载](https://github.com/getActivity/Logcat/releases/download/11.8/Logcat.apk)
![](picture/demo_code.png)
@@ -51,7 +51,7 @@ dependencyResolutionManagement {
```groovy
dependencies {
// 日志调试框架:https://github.com/getActivity/Logcat
- debugImplementation 'com.github.getActivity:Logcat:11.6'
+ debugImplementation 'com.github.getActivity:Logcat:11.8'
}
```
@@ -66,6 +66,18 @@ android.enableJetifier = true
* 如果项目是基于 **Support** 包则不需要加入此配置
+#### compileSdk 版本要求
+
+* 如果项目的 `compileSdkVersion` 小于 29,则需要先升级成 29
+
+```groovy
+android {
+ compileSdkVersion 29
+}
+```
+
+* 如果项目的 `compileSdkVersion` 大于等于 29,则不需要修改此配置
+
#### 使用方式
* 无需调用,直接运行,然后授予悬浮窗权限即可
diff --git a/app/build.gradle b/app/build.gradle
index 28f417e..8348bf9 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -7,8 +7,8 @@ android {
applicationId "com.hjq.logcat.demo"
minSdk 16
targetSdk 34
- versionCode 1160
- versionName "11.6"
+ versionCode 1180
+ versionName "11.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
diff --git a/build.gradle b/build.gradle
index 8e48b57..2af3723 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,6 +2,6 @@ plugins {
id 'com.android.application' version '7.1.0' apply false
}
-task clean(type: Delete) {
+tasks.register('clean', Delete) {
delete rootProject.buildDir
}
\ No newline at end of file
diff --git a/library/build.gradle b/library/build.gradle
index f1528de..1420910 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion 16
- versionCode 1160
- versionName "11.6"
+ versionCode 1180
+ versionName "11.8"
}
lintOptions {
diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml
index 271cc4f..91f3b34 100644
--- a/library/src/main/AndroidManifest.xml
+++ b/library/src/main/AndroidManifest.xml
@@ -10,12 +10,8 @@
-
-
-
+
+
@@ -40,9 +36,8 @@
Unable to start service com.hjq.logcat.LogcatService with Intent:
android.app.MissingForegroundServiceTypeException:
Starting FGS without a type callerApp=ProcessRecord targetSDK=34 -->
-
-
-
+
+
diff --git a/library/src/main/java/com/hjq/logcat/LogcatService.java b/library/src/main/java/com/hjq/logcat/LogcatService.java
index 67267fa..3ed9737 100644
--- a/library/src/main/java/com/hjq/logcat/LogcatService.java
+++ b/library/src/main/java/com/hjq/logcat/LogcatService.java
@@ -1,6 +1,6 @@
package com.hjq.logcat;
-import android.app.Notification;
+import android.app.Notification.Builder;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -8,8 +8,11 @@
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;
import android.text.TextUtils;
@@ -32,8 +35,8 @@ public IBinder onBind(Intent intent) {
public int onStartCommand(Intent intent, int flags, int startId) {
Intent notificationIntent = new Intent(this, LogcatActivity.class);
int pendingIntentFlag;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
- getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.S) {
+ if (VERSION.SDK_INT >= VERSION_CODES.S &&
+ getApplicationInfo().targetSdkVersion >= VERSION_CODES.S) {
// Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
// Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g.
// if it needs to be used with inline replies or bubbles.
@@ -48,7 +51,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
applicationName = getPackageName();
}
- Notification.Builder builder = new Notification.Builder(this)
+ Builder builder = new Builder(this)
// 设置大图标,不设置则默认为程序图标
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logcat_floating_normal))
// 设置标题
@@ -60,7 +63,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
.setContentIntent(pendingIntent);
// 设置通知渠道
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ if (VERSION.SDK_INT >= VERSION_CODES.O) {
// 通知渠道的id
String notificationChannelId = "logcat";
NotificationChannel channel = new NotificationChannel(notificationChannelId,
@@ -79,15 +82,20 @@ public int onStartCommand(Intent intent, int flags, int startId) {
builder.setChannelId(notificationChannelId);
} else {
// 关闭声音通知
- builder.setSound(null);
- // 关闭震动通知
- builder.setVibrate(null);
- // 关闭闪光灯通知
- builder.setLights(0, 0, 0);
+ builder.setSound(null)
+ // 关闭震动通知
+ .setVibrate(null)
+ // 关闭闪光灯通知
+ .setLights(0, 0, 0);
}
// 将服务和通知绑定在一起,成为前台服务
- startForeground(BACKUP_SERVICE_NOTIFICATION_ID, builder.build());
+ 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());
+ }
return super.onStartCommand(intent, flags, startId);
}