1.在AndroidManifest.xml文件中添加权限
2.在Activity的onCreate()函数中添加请求不熄屏的代码: getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
package org.venus.wd; import android.os.Bundle; import android.view.WindowManager; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)