如何保持在屏幕上我的应用程序? [英] How do I keep the screen on in my App?

查看:101
本文介绍了如何保持在屏幕上我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的Andr​​oid应用我再也不想在手机锁定或背光关闭

For my Android app I never want the phone to lock or the back light to turn off

推荐答案

使用 PowerManager.WakeLock 类序执行此。 请参见下面的code:

Use PowerManager.WakeLock class inorder to perform this. See the following code:

import android.os.PowerManager;

public class MyActivity extends Activity {

    protected PowerManager.WakeLock mWakeLock;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(final Bundle icicle) {
        setContentView(R.layout.main);

        /* This code together with the one in onDestroy() 
         * will make the screen be always on until this Activity gets destroyed. */
        final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
        this.mWakeLock.acquire();
    }

    @Override
    public void onDestroy() {
        this.mWakeLock.release();
        super.onDestroy();
    }
}

使用的follwing许可清单文件:

Use the follwing permission in manifest file :

<uses-permission android:name="android.permission.WAKE_LOCK" />

希望这将解决您的问题...:)

Hope this will solve your problem...:)

这篇关于如何保持在屏幕上我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆