问题
I am creating an game using accelerometer in libgdx and while playing the game, it sleeps after some, i need awake this untill game-play. i got this in some forums
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
which work for android app,but don't how to do that in libgdx, it is unrecognizable by compiler.any help will be appreciated.
回答1:
Best and easiest way to do that is
Go to the android folder of your project in android studio
then locate AndroidLauncher.java in src sub-folder
then copy and paste code below
@Override protected void createWakeLock(boolean use) { use=true; super.createWakeLock(use); }
after adding code whole file will look like this
public class AndroidLauncher extends AndroidApplication { @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); initialize(new MyBomber(), config);
}
@Override protected void createWakeLock(boolean use) { use=true; super.createWakeLock(use); } }
回答2:
onCreate
method of AndoridLauncher create a configuration object and set useWakelock=true
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useWakelock=true;
initialize(new MyGdxGame(), config);
来源:https://stackoverflow.com/questions/40160469/how-to-awake-screen-while-game-play-in-libgdx