Skip to content

Commit

Permalink
fix WindowManager crash on android 11+ (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
wenxi-zeng authored May 12, 2023
1 parent 3f55ae7 commit 000349d
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,17 @@ public AnalyticsContext putReferrer(Referrer referrer) {
*/
void putScreen(Context context) {
Map<String, Object> screen = createMap();
WindowManager manager = getSystemService(context, Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
context.getDisplay().getRealMetrics(displayMetrics);
}
else {
WindowManager manager = getSystemService(context, Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
display.getMetrics(displayMetrics);
}

screen.put(SCREEN_DENSITY_KEY, displayMetrics.density);
screen.put(SCREEN_HEIGHT_KEY, displayMetrics.heightPixels);
screen.put(SCREEN_WIDTH_KEY, displayMetrics.widthPixels);
Expand Down

0 comments on commit 000349d

Please sign in to comment.