2 個方法:

1. 由powermanager 入手....

protected PowerManager.WakeLock mWakeLock;

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        
         /* 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() {
             utils.log("onDestroy ... ");
                this.mWakeLock.release();
                super.onDestroy();
            }

2. 由window 入有..

開:
getWindow
().addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


關:
getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
arrow
arrow
    全站熱搜

    lionlionchopper 發表在 痞客邦 留言(0) 人氣()