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;


  • 相关阅读:
    asp.net 中的viewstate用法?
    .net中 过滤 指定 字符串
    js中replace的用法
    restart
    外部函数
    JQuery实现Ajax 根据商品名称自动显示价格
    ListView中命令行按钮应用;
    GridView中获取行数和列数
    全局应用程序类Global
    如何获取gridview中模板列中控件的值?
  • 原文地址:https://www.cnblogs.com/bill-technology/p/4130820.html
Copyright © 2011-2022 走看看