У меня есть приложение, которое поддерживает отображение наложения экрана (с разрешением SYSTEM_ALERT_WINDOW
).
Я реализовал KEYCODE_BACK
и прослушиватель домашнего нажатия, чтобы удалить его наложение.
val wrapper = object : FrameLayout(this) {
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
return when (event.keyCode) {
KeyEvent.KEYCODE_BACK -> {
deleteContentView()
true
}
else -> {
super.dispatchKeyEvent(event)
}
}
}
//if pressed home key,
fun onCloseSystemDialogs(reason: String) {
//The Code Want to Perform.
deleteContentView()
}
}
contentView = LayoutInflater.from(this).inflate(R.layout.layout_overlay, wrapper)
Он работает в режиме отладки с ProGuard или R8 не активирован. Когда я создал релиз apk, этот прослушиватель домашнего пресса не работал.
Я не знаю, что onCloesSystemDialogs()
не вызывается никаким другим методом в приложении, поэтому я разрешил KEYCODE_BACK
call onCloseSystemDialogs
, думаю больше не будет сжиматься.
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
return when (event.keyCode) {
KeyEvent.KEYCODE_BACK -> {
onCloseSystemDialogs("")
true
}
else -> {
super.dispatchKeyEvent(event)
}
}
}
Но все равно не работает. В любом случае, позволить Proguard или R8 не сжимать эту часть кода? Спасибо.
Это мой build.gradle
buildTypes {
debug {
applicationIdSuffix '.debug'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "app_name", "My app (Dev)"
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
resValue "string", "app_name", "My app"
}
}
Мой файл ProGuard
-keepattributes Signature
-keepattributes *Annotation*
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }
# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}
##---------------End: proguard configuration for Gson ----------
-keep class io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class * { *; }
-dontwarn javax.**
-keepnames public class * extends io.realm.RealmObject
-dontwarn io.realm.**