首页 > 解决方案 > React Native - 如何保持屏幕开启?无博览会

问题描述

你需要让你的手机继续使用以更好地编码吗?

MainActivity.java我们通常有这个

文件: MainActivity.java

package com.client;

import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {
  
   /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */

  @Override
  protected String getMainComponentName() {
    return "client";
  }


}

您可以添加一些行以使您的手机始终保持开启以更好地进行编码,这些行代码不会让您的手机唤醒。

解决方案

package com.client;

import com.facebook.react.ReactActivity;
import android.os.Bundle;
import android.view.WindowManager;

public class MainActivity extends ReactActivity {
  
   /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */

  @Override
  protected String getMainComponentName() {
    return "client";
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().
      addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  }

}

标签: javareact-native

解决方案


推荐阅读