File tree 1 file changed +11
-3
lines changed
OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -4,17 +4,18 @@ import android.app.Activity
4
4
import android.content.Context
5
5
import android.graphics.Rect
6
6
import android.net.ConnectivityManager
7
+ import android.os.Build
7
8
import android.telephony.TelephonyManager
8
9
import android.util.DisplayMetrics
9
10
import android.view.View
11
+ import androidx.core.view.WindowInsetsCompat
10
12
import java.lang.ref.WeakReference
11
13
12
14
object DeviceUtils {
13
15
private val MARGIN_ERROR_PX_SIZE = ViewUtils .dpToPx(24 )
14
16
15
17
/* *
16
18
* Check if the keyboard is currently being shown.
17
- * Does not work for cases when keyboard is full screen.
18
19
*/
19
20
fun isKeyboardUp (activityWeakReference : WeakReference <Activity ?>): Boolean {
20
21
val metrics = DisplayMetrics ()
@@ -28,8 +29,15 @@ object DeviceUtils {
28
29
window.windowManager.defaultDisplay.getMetrics(metrics)
29
30
}
30
31
if (view != null ) {
31
- val heightDiff = metrics.heightPixels - visibleBounds.bottom
32
- isOpen = heightDiff > MARGIN_ERROR_PX_SIZE
32
+ isOpen =
33
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
34
+ val imeInsets = view.rootWindowInsets
35
+ imeInsets.isVisible(WindowInsetsCompat .Type .ime())
36
+ } else {
37
+ // Does not work for cases when keyboard is full screen for Android 9 and below
38
+ val heightDiff = metrics.heightPixels - visibleBounds.bottom
39
+ heightDiff > MARGIN_ERROR_PX_SIZE
40
+ }
33
41
}
34
42
return isOpen
35
43
}
You can’t perform that action at this time.
0 commit comments