I'm Developing an Android Application where it requireds 3 things:-
- To keep the App up an running for specific time and then phone will be off (Working Fine)
- 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).
- 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)
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!
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
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"
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
For Lenovo A2010 phone,following worked:
- Use file manager phone app from playstore like Total commander(on rooted phone) to goto folder /system/bin/
- Copy file kpoc_charger and paste it there as kpoc_charger.bak
Now edit the original file kpoc_charger using total-commander, replace all lines with following code:
#!/system/bin/sh /system/bin/reboot
- 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).
- Now shutdown phone and plug to charger.
- Bazinga!!!! battery icon shows for a sec but phone sucessfully boots into os.
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.
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)
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());
}
}
}
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.
来源:https://stackoverflow.com/questions/26294258/auto-boot-when-wall-charger-is-plugged