17

I'm Developing an Android Application where it requireds 3 things:-

  1. To keep the App up an running for specific time and then phone will be off (Working Fine)
  2. When phone get charging from outlet, I want phone to power up automatically without hitting any power button. (Not Working with wall Socket, but working when connected to USB cable via Laptop).
  3. After boot my app should start working Automatically (Working Fine)

You Must know :- My phone is Moto E (rooted) and want 2nd step to be done. Tried some codes but that does not work on moto E. When Connected with USB it gives 2 as response and when connected with Wall socket charger it says 1

Any help will be Appreciated

P.S :- Auto Boot working with USB cable connected with Laptop but not with Socket Charger

Update-1: 1- Found fastboot oem off-mode-charge 0 working with Nexus 7 but not on Moto e.

2- Moto e boots when connected to Router (USB Dongle Port)

Rohit
  • 821
  • 2
  • 8
  • 34

10 Answers10

11

At last I got the solution, you can achieve this by deleting system/bin/charge_only_mode file. Please do that at your own risk and before deleting have backup of that file. I got the desired result that was boot when its connected to wall charger and now its working fine. All the best!

Rohit
  • 821
  • 2
  • 8
  • 34
  • I tried editing that file by pulling it from device onto my machine by opening in a file editor. It seems to be a binary file and I am not sure how to edit. Could you please give me directions on where to edit and what to edit! – nagamanojv Nov 14 '14 at 12:10
  • I just deleted that file after taking backup of that. No editing nothing else . Used ES file explorer and then in Menu>Tools>Root Explorer (Turned That ON) and then copied that file somewhere and then deleted that file. – Rohit Nov 15 '14 at 06:14
  • @Rohit: Do you know the command using which we can turn off the backlight during the booting up stage (the stage where the battery anim is showed)? – Basher51 Dec 30 '14 at 10:25
  • Lenovo S6000-H doesn't have "system/bin/charge_only_mode" or "/system/bin/chargemon" or "/system/bin/playlpm"!!! Take a look at this http://android.stackexchange.com/questions/131062/lenovo-s6000-auto-power-on-after-connecting-charger. How can I do this on S6000? : – mohammads Dec 13 '15 at 07:31
  • This file is not present on a Motorola Moto E (condor) :( – Jon Pawley Apr 03 '19 at 04:03
5

Moto e4 and Pixel 2 XL:

Get your device into the bootloader (fastboot) and run the following command from a computer connected over USB with Android Tools:

fastboot oem off-mode-charge 0

Mad Scientist Moses
  • 1,029
  • 1
  • 10
  • 10
2

I was able to get it to work by updating the init.rc file

I found the on charger trigger and added the following lines below it:

setprop ro.bootmode "normal"
setprop sys.powerctl "reboot"

The entire trigger block ends up looking like this

on charger
    class_start charger
    setprop ro.bootmode "normal"
    setprop sys.powerctl "reboot"

You then need to repack and flash the boot image created after the updates.

Connect the device over USB

Power on device and get to bootloader mode

adb reboot bootloader 

To flash boot image execute the following command while in fastboot

fastboot flash boot new-boot.img

Note: This fix will cause the device to reboot when its plugged in even when shutting it off using the power button or software shutdown.

Source: https://forum.xda-developers.com/showthread.php?p=77766638#post77766638

You can see the commit that contains these changes for my project here:

https://github.com/darran-kelinske-fivestars/mkbootimg_tools/commit/c8633a2ec2e1924272fd16a8ed7fa7414bb65544#diff-d0007d763b44198f7c22e2c19609d5bbR606

dazza5000
  • 5,339
  • 6
  • 34
  • 67
1

I also tried replacing charge_only_mode with a sh script that rebooted the phone but only got a red circle with the M (on a Motorola Bionic). Changing the script to the below got it working...Now I get the red circle with the M for a few seconds, then a blank screen, the another red circle with the M, and it boots on up.

#!/system/bin/sh
su -c "/system/bin/reboot -n outofcharge"
1

On my device Lenovo K7000-Plus, the file need to be modified is kpoc_charger located at /system/bin.

Ipod file not working on my phone which using Android 6.0 ROM, but kpoc_charger works pefectly.

Regards

Hadi

Ingo Karkat
  • 154,018
  • 15
  • 205
  • 275
Hadi
  • 11
  • 1
1

For Lenovo A2010 phone,following worked:

  1. Use file manager phone app from playstore like Total commander(on rooted phone) to goto folder /system/bin/
  2. Copy file kpoc_charger and paste it there as kpoc_charger.bak
  3. Now edit the original file kpoc_charger using total-commander, replace all lines with following code:

    #!/system/bin/sh
    /system/bin/reboot
    
  4. Save it, goto properties and change UID:0 root, GID:2000 shell and permission as 755 (same as properties of other files in /system/bin folder).
  5. Now shutdown phone and plug to charger.
  6. Bazinga!!!! battery icon shows for a sec but phone sucessfully boots into os.
0

When phone get charging from outlet, I want phone to power up automatically without hitting any power button. (Not Working with wall Socket, but working when connected to USB cable via Laptop).

You can only achieve this by modifying your phone's OS files. Basically there is boot script/binary at /system/bin/chargemon which you can replace with a script that does nothing. Do it at your own risk because this may result in the device being damaged permanently. Also, Manufacturer warranty will become void.

S.D.
  • 28,125
  • 2
  • 75
  • 122
0

I found another way for this (thanks to DavidThompson256 http://forum.xda-developers.com/showthread.php?t=1187631)

First make sure your phone is rooted (which I found iRoot very good for this), then install RootExplorer.apk (or similar) on your phone.

Try to edit "/system/bin/playlpm" and replace its content with following commands: (do not forget to make a backup first).

#!/system/bin/sh
/system/bin/reboot

(I know the content is in binary, simply remove them and write those two lines and save the file)

NOTE: When you modify that file, no changes will be applied on its permissions but if you are making another file remember to set permissions exactly as it was.

Finally, please do it on your own risk. It worked for me. (Samsung Discovery S730M)

Amir Dashti
  • 349
  • 3
  • 13
-1

i think there should be power sensor if you can add that in this code i belive it will work

public class Main extends Activity {
        private SensorManager mSensorManager;
        private PowerManager mPowerManager;
        private WindowManager mWindowManager;
        private WakeLock mWakeLock;
        private Button button;
        private TextView textView;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
try{
            // Get an instance of the SensorManager
            mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

            // Get an instance of the PowerManager
            mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);

            // Get an instance of the WindowManager
            mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
            mWindowManager.getDefaultDisplay();

            // Create a bright wake lock
            mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass()
                    .getName());

            setContentView(R.layout.main);
            textView = (TextView)findViewById(R.id.textView1);
            button = (Button)findViewById(R.id.button1);
            button.setOnClickListener(mButtonStopListener);


        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Log.e("onCreate", e.getMessage());
        }
} // END onCreate

        View.OnClickListener mButtonStopListener = new OnClickListener() {
            public void onClick(View v) {
                try {
                    mWakeLock.release();
                    textView.setText("mWakeLock.release()");
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Log.e("onPause",e.getMessage());
                }

            }
        };

        @Override
        protected void onResume() {
            super.onResume();
            /*
             * when the activity is resumed, we acquire a wake-lock so that the
             * screen stays on, since the user will likely not be fiddling with the
             * screen or buttons.
             */

            try {
                mWakeLock.acquire();
                textView.setText("mWakeLock.acquire()");
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.e("onResume", e.getMessage());
            }

        }

        @Override
        protected void onPause() {
            super.onPause();

            // and release our wake-lock
            try {
                mWakeLock.release();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.e("onPause",e.getMessage());
            }
        }
}
Boldbayar
  • 793
  • 7
  • 20
  • 2
    How will this work when the OP states that he intends to boot up the device when its powered up using the USB cable? In short,when the device is off,no app is running and hence your code won't even execute. This kind of functionality is embedded in the bootloader before the Android OS boots up.IMO,we need to modify the kernel level files to achieve the result. – Basher51 Nov 10 '14 at 13:28
  • at last i found the solution and its 100 % working now. – Rohit Nov 12 '14 at 06:08
  • @Rohit: Can you post the solution that is 100% working for you. I also have the same requirement on a rooted device. – nagamanojv Nov 14 '14 at 08:02
  • Yes, please let us know your solution @Rohit. I am rooted and I was able to remove the "charge_only_mode" file, but now when I plug into a wall charger I just get the red circle with Moto "M", and I have to pull the battery to reset. Thank you. – EddieB Jan 16 '15 at 20:07
  • I have mentioned the solution . Please check at the top and am using same thing with my 20 Moto E devices . – Rohit Jan 17 '15 at 06:38
-1

So I was trying to achieve this with a 3rd gen Moto G. It has a charge_only_mode file as per Rohit's answer, but simply moving/renaming it did not make the phone reboot on charge. Instead it just sat there with a Motorola logo. I got the same result when replacing charge_only_mode with either of the scripts referenced here.

I did get it to work, however. I copied /system/bin/reboot into /system/bin/charge_only_mode, and that did the trick.

Dave
  • 1