Try this:
1. Create file “MainActivity.java” in Assets folder.
2. Open this file and paste code:
package com.*YOUR COMPANY NAME*.*YOUR PRODUCT NAME*;
import com.unity3d.player.UnityPlayerActivity;
import android.os.Bundle;
import android.os.Build;
import android.view.Display;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends UnityPlayerActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Window w = getWindow();
WindowManager.LayoutParams p = w.getAttributes();
Display.Mode[] modes = getDisplay().getSupportedModes();
//find display mode with max hz
int maxMode = 0;
float maxHZ = 60f;
for(Display.Mode m:modes) {
if (maxHZ < m.getRefreshRate()) {
maxHZ = m.getRefreshRate();
maxMode = m.getModeId();
}
}
p.preferredDisplayModeId = maxMode;
w.setAttributes(p);
}
}
}
3. Change YOUR COMPANY NAME and YOUR PRODUCT NAME to Company Name and Product Name from Project Settings → Player.
4. Go to Project Settings → Player → Publishing Settings. Tick “Custom Main Manifest”.
5. Open file “AndroidManifest.xml” in “*Assets\Plugins\Android*”.
6. Change android:name=“com.unity3d.player.UnityPlayerActivity” to android:name=“com.YOUR COMPANY NAME.YOUR PRODUCT NAME.MainActivity”.
7. Be sure to call “Application.targetFrameRate = Screen.currentResolution.refreshRate;” in any script!
Update: fixed bug in Android 12.