猿问

是否可以覆盖断电操作?

我正在尝试修改或覆盖 android 中电源关闭菜单按钮的功能(不是屏幕开/关按钮)。

我想在设备关闭之前触发一个进程,运行一个进程,然后关闭设备

如果这可能吗?


慕村225694
浏览 59回答 2
2回答

白板的微信

是的,这是可能的。您不必拥有根设备,只需使用广播即可。在清单中:<receiver android:name="com.example.broadcastreceiver.YourClass">&nbsp; &nbsp; <intent-filter>&nbsp; &nbsp; &nbsp; &nbsp; <action android:name="android.intent.action.ACTION_SHUTDOWN" />&nbsp; &nbsp; </intent-filter></receiver>你的班:public class YourClass extends BroadcastReceiver {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void onReceive(Context c, Intent i) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(i.getAction().equals("android.intent.action.ACTION_SHUTDOWN")){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Fire your code here&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }};}如果听起来不可能,请找到另一种方法来做同样的事情;)

慕尼黑的夜晚无繁华

简单的回答:没有。对于有限数量的设备,如果不对您的固件或 Android 操作系统的核心进行&nbsp;自定义修改,这是不可能的。更多信息因此,在有根设备上,您也许可以做到这一点。检查此链接。
随时随地看视频慕课网APP

相关分类

Java
我要回答