fix android sdk 34 崩溃 java.lang.SecurityException: ... One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified 是因为您的应用目标 SDK 为 Android 14 (API 34)。
fix android sdk 34 崩溃 java.lang.SecurityException: ... One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified 是因为您的应用目标 SDK 为 Android 14 (API 34)。
This commit is contained in:
@@ -5,6 +5,8 @@ import android.content.BroadcastReceiver
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
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.constants.Intents
|
||||||
import com.github.kr328.clash.common.log.Log
|
import com.github.kr328.clash.common.log.Log
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -88,7 +90,7 @@ class Broadcasts(private val context: Application) {
|
|||||||
return
|
return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context.registerReceiver(broadcastReceiver, IntentFilter().apply {
|
val filter = IntentFilter().apply {
|
||||||
addAction(Intents.ACTION_SERVICE_RECREATED)
|
addAction(Intents.ACTION_SERVICE_RECREATED)
|
||||||
addAction(Intents.ACTION_CLASH_STARTED)
|
addAction(Intents.ACTION_CLASH_STARTED)
|
||||||
addAction(Intents.ACTION_CLASH_STOPPED)
|
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_COMPLETED)
|
||||||
addAction(Intents.ACTION_PROFILE_UPDATE_FAILED)
|
addAction(Intents.ACTION_PROFILE_UPDATE_FAILED)
|
||||||
addAction(Intents.ACTION_PROFILE_LOADED)
|
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
|
clashRunning = StatusClient(context).currentProfile() != null
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -110,10 +120,11 @@ class Broadcasts(private val context: Application) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
context.unregisterReceiver(broadcastReceiver)
|
context.unregisterReceiver(broadcastReceiver)
|
||||||
|
registered = false
|
||||||
|
|
||||||
clashRunning = false
|
clashRunning = false
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w("Unregister global receiver: $e", e)
|
Log.w("Unregister global receiver: $e", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -406,7 +406,7 @@
|
|||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:id="@+id/view_accountinfo5"
|
android:id="@+id/view_accountinfo5"
|
||||||
android:background="@color/white"
|
android:background="@color/white"
|
||||||
|
android:backgroundTint="@color/white"
|
||||||
app:cardElevation="4dp"
|
app:cardElevation="4dp"
|
||||||
app:cardCornerRadius="6dp"
|
app:cardCornerRadius="6dp"
|
||||||
android:layout_margin="4dp" >
|
android:layout_margin="4dp" >
|
||||||
|
|||||||
Reference in New Issue
Block a user