zoukankan      html  css  js  c++  java
  • 解决:在低电量关机的同时自动挂断电话电话

    首先我们通过定位找到低电量自动关机的代码:

    相关类:service/java/com/android/server/BatteryService.java

    相关方法:shutdownIfNoPowerLocked()

    修改后代码(红色部分为关键代码):

    private void shutdownIfNoPowerLocked() {

            // shut down gracefully if our battery is critically low and we are not powered.

            // wait until the system has booted before attempting to display the shutdown dialog.

            if (mBatteryProps.batteryLevel == 0 && !isPoweredLocked(BatteryManager.BATTERY_PLUGGED_ANY)) {

                mHandler.post(new Runnable() {

                    @Override

                    public void run() {

                        if (ActivityManagerNative.isSystemReady()) {

                            if (FeatureOption.MTK_IPO_SUPPORT == true) {

                                SystemProperties.set("sys.ipo.battlow","1");

                            }

                            try {

                                ITelephony iTelephony = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));

                                if (iTelephony != null) {

                                    iTelephony.endCall();

                                }

                            } catch (Exception e) {

                                e.printStackTrace();

                            }

                            Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);

                            intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);

                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                            mContext.startActivityAsUser(intent, UserHandle.CURRENT);

                        }

                    }

                });

            }

        }

    另外不要忘记引入相关库:

    import com.android.internal.telephony.ITelephony;


  • 相关阅读:
    Java多线程详解
    自动化构建工具Maven
    解决 安装cocoapods失败,提示 requires Ruby version >=2.2.2
    安装Cocoapods时候ERROR: While executing gem ... (Errno::EPERM)
    iOS可执行文件瘦身方法
    ios webview自适应实际内容高度4种方法
    iOS8 tableview separatorInset cell分割线左对齐,ios7的方法失效了
    Reveal1.5破解,iOS_UI调试利器Reveal最新版本破解方法
    Xcode安装插件,错误选择了Skip Bundles,重新出现Load Bundles方法
    10分钟搞定支付宝支付 的 各种填坑
  • 原文地址:https://www.cnblogs.com/bill-technology/p/4130820.html
Copyright © 2011-2022 走看看