From 29fac310a3073cdb2faebe4fb962309daad472fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=B2=E9=98=B3?= Date: Tue, 20 Aug 2024 15:26:21 +0800 Subject: [PATCH] =?UTF-8?q?api=E5=8D=87=E7=BA=A734=20=E9=80=82=E9=85=8Dand?= =?UTF-8?q?roid14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- updateapp/build.gradle | 4 ++-- .../kotlin/updateapp/update/UpdateAppService.kt | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/updateapp/build.gradle b/updateapp/build.gradle index 329d8b5..aa50c35 100644 --- a/updateapp/build.gradle +++ b/updateapp/build.gradle @@ -2,12 +2,12 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 30 + compileSdkVersion 34 defaultConfig { minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 34 versionCode 1 versionName "1.0" diff --git a/updateapp/src/main/kotlin/updateapp/update/UpdateAppService.kt b/updateapp/src/main/kotlin/updateapp/update/UpdateAppService.kt index 9230d39..62e1373 100644 --- a/updateapp/src/main/kotlin/updateapp/update/UpdateAppService.kt +++ b/updateapp/src/main/kotlin/updateapp/update/UpdateAppService.kt @@ -3,7 +3,9 @@ package update import android.app.Service import android.content.Intent import android.content.IntentFilter +import android.os.Build import android.os.IBinder +import android.content.Context.RECEIVER_EXPORTED /** * desc: UpdateAppService @@ -15,8 +17,15 @@ internal class UpdateAppService : Service() { override fun onCreate() { super.onCreate() // 动态注册receiver 适配8.0 updateAppReceiver 静态注册没收不到广播 - registerReceiver(updateAppReceiver, IntentFilter(packageName + UpdateAppReceiver.ACTION_UPDATE)) - registerReceiver(updateAppReceiver, IntentFilter(packageName + UpdateAppReceiver.ACTION_RE_DOWNLOAD)) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + registerReceiver(updateAppReceiver, IntentFilter(packageName + UpdateAppReceiver.ACTION_UPDATE), RECEIVER_EXPORTED) + registerReceiver(updateAppReceiver, IntentFilter(packageName + UpdateAppReceiver.ACTION_RE_DOWNLOAD), RECEIVER_EXPORTED) + }else { + registerReceiver(updateAppReceiver, IntentFilter(packageName + UpdateAppReceiver.ACTION_UPDATE)) + registerReceiver(updateAppReceiver, IntentFilter(packageName + UpdateAppReceiver.ACTION_RE_DOWNLOAD)) + } + } override fun onDestroy() {