Android 4次电源按钮按下呼叫功能

Android 4次电源按钮按下呼叫功能,android,Android,我已经创建了一个发送SMS和调用callfunction()函数的方法 我想在用户按下四次电源按钮后调用该功能,它不要求应用程序处于已启动状态。尝试使用 部分尾流锁定 在API级别1中添加 int部分唤醒锁定 唤醒锁定级别:确保CPU正在运行;屏幕和键盘背光将允许熄灭 如果用户按下电源按钮,则屏幕将关闭,但CPU将保持打开,直到所有部分唤醒锁释放 常量值:1(0x00000001) 例如: //Initialize the Power Manager PowerManager pm = (Pow

我已经创建了一个发送
SMS
和调用
callfunction()函数的方法
我想在用户按下四次电源按钮后调用该功能,它不要求应用程序处于已启动状态。

尝试使用

部分尾流锁定

在API级别1中添加 int部分唤醒锁定 唤醒锁定级别:确保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();
 }
要操作电源按钮,请查看此帖子:


这只是一个假设,如果它仍然不起作用,您是否可以发布一些日志或更多项目的代码片段:)

我认为这不可能跟踪电源按钮按下4次并启动预期功能。因为我在play store上找不到任何具有这种功能的应用程序,所以我可以从那里开始工作。 但按下电源按钮1次将触发