2017-12-13 9 views

答えて

2

は、APIレベルで追加Power Manager

PARTIAL_WAKE_LOCKを使用してみてください1 int型PARTIAL_WAKE_LOCK ウェイクロックレベル:CPUが動作していることを確認します。画面とキーボードのバックライトが消灯します。

ユーザーが電源ボタンを押した場合、画面はオフになりますが、CPUは、すべての部分的なウェイクロックが解除されるまで、オンになります。

定数値:1(0x00000001の)

例:

//Initialize the Power Manager 
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 

//Create a PARTIAL_WAKE_LOCK 
//This will keep the cpu running in the Background, so that the function will be called on the desired Time 
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag"); 

//Check if the WackLock is held (may throw erro if you try to acquire twice) 
//TRUE --> Do nothing, all good 
//FALSE --> Acquire the WakeLock 
if(!wl.isHeld()){ 
    wl.acquire(); 
} 

//***** 
//You code to handel the Powerbutton comes here 
//***** 

//If the Repeating task is not active, release the Lock 

//Check if the WackLock is held (may throw error if you try to release a none acquired Lock) 
//TRUE --> Release Lock 
//FALSE --> Do nothing, all good 
if(wl.isHeld()){ 
    wl.release(); 
} 

このポストを確認し、電源ボタンを処理するには: How to hook into the Power button in Android?

それならばこれは、単なる仮定でありますそれでもまだ動作しない場合、プロジェクトのいくつかのログまたはコードスニペットを投稿することができます:)

0

これは、電源ボタンを4回押し続けたり、予想される機能を開始することができないと思います。私はこの種の機能を持っているプレイストアでは、尊敬されている仕事を始めるためのアプリは見つけられません。 しかし、電源ボタンを1回押すとトリガーがかかります。

関連する問題