Detect power button long press

前端 未结 11 2338
轮回少年
轮回少年 2020-11-27 18:38

I\'ve been reading some posts here on Stackoverflow, and I didn\'t find a good solution, I\'m wondering if it\'s possible to detect when the user long press the power button

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 19:20

    I see many answers trying to hookin to the powerbutton. However, wouldn't it be more easy to listen for the shutdown event? I'm not sure if this fits your need, but it seems like it.

    Simply register a Broadcastreceiver to the following action(s):

    
        
            
            
        
    
    

    Don't forget to add the following permission:

提交回复
热议问题