From afd459c7652676066523b3625908fb113694c10d Mon Sep 17 00:00:00 2001 From: zeus Date: Wed, 24 Dec 2025 12:17:16 +0800 Subject: [PATCH] =?UTF-8?q?fix=20android=20sdk=2034=20=E5=B4=A9=E6=BA=83?= =?UTF-8?q?=20java.lang.SecurityException:=20...=20One=20of=20RECEIVER=5FE?= =?UTF-8?q?XPORTED=20or=20RECEIVER=5FNOT=5FEXPORTED=20should=20be=20specif?= =?UTF-8?q?ied=20=E6=98=AF=E5=9B=A0=E4=B8=BA=E6=82=A8=E7=9A=84=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E7=9B=AE=E6=A0=87=20SDK=20=E4=B8=BA=20Android=2014=20?= =?UTF-8?q?(API=2034)=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix android sdk 34 崩溃 java.lang.SecurityException: ... One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified 是因为您的应用目标 SDK 为 Android 14 (API 34)。 --- .../com/github/kr328/clash/remote/Broadcasts.kt | 17 ++++++++++++++--- .../src/main/res/layout/activity_profile.xml | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Android-kotlin-Code/app/src/main/java/com/github/kr328/clash/remote/Broadcasts.kt b/Android-kotlin-Code/app/src/main/java/com/github/kr328/clash/remote/Broadcasts.kt index 51d0692..75d3dcb 100644 --- a/Android-kotlin-Code/app/src/main/java/com/github/kr328/clash/remote/Broadcasts.kt +++ b/Android-kotlin-Code/app/src/main/java/com/github/kr328/clash/remote/Broadcasts.kt @@ -5,6 +5,8 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import android.os.Build +import androidx.core.content.ContextCompat import com.github.kr328.clash.common.constants.Intents import com.github.kr328.clash.common.log.Log import java.util.* @@ -88,7 +90,7 @@ class Broadcasts(private val context: Application) { return try { - context.registerReceiver(broadcastReceiver, IntentFilter().apply { + val filter = IntentFilter().apply { addAction(Intents.ACTION_SERVICE_RECREATED) addAction(Intents.ACTION_CLASH_STARTED) addAction(Intents.ACTION_CLASH_STOPPED) @@ -96,7 +98,15 @@ class Broadcasts(private val context: Application) { addAction(Intents.ACTION_PROFILE_UPDATE_COMPLETED) addAction(Intents.ACTION_PROFILE_UPDATE_FAILED) addAction(Intents.ACTION_PROFILE_LOADED) - }) + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + context.registerReceiver(broadcastReceiver, filter, Context.RECEIVER_EXPORTED) + } else { + context.registerReceiver(broadcastReceiver, filter) + } + + registered = true clashRunning = StatusClient(context).currentProfile() != null } catch (e: Exception) { @@ -110,10 +120,11 @@ class Broadcasts(private val context: Application) { try { context.unregisterReceiver(broadcastReceiver) + registered = false clashRunning = false } catch (e: Exception) { Log.w("Unregister global receiver: $e", e) } } -} \ No newline at end of file +} diff --git a/Android-kotlin-Code/design/src/main/res/layout/activity_profile.xml b/Android-kotlin-Code/design/src/main/res/layout/activity_profile.xml index c53f6f6..88ca3e6 100644 --- a/Android-kotlin-Code/design/src/main/res/layout/activity_profile.xml +++ b/Android-kotlin-Code/design/src/main/res/layout/activity_profile.xml @@ -406,7 +406,7 @@ android:layout_marginTop="16dp" android:id="@+id/view_accountinfo5" android:background="@color/white" - + android:backgroundTint="@color/white" app:cardElevation="4dp" app:cardCornerRadius="6dp" android:layout_margin="4dp" >