How to Reboot phone programmatically?

前端 未结 5 1452
情深已故
情深已故 2021-01-17 04:27

I am creating app(only for Android 6) in which I have to give reboot functionality using button click. I am using following code:

PowerManager pm =(PowerMan         


        
5条回答
  •  独厮守ぢ
    2021-01-17 05:24

    As per the answer of @Maňish Yadav your app should be device owner to do rebooting due to security reasons.

    You cannot do a reboot from an ordinary SDK application. Only applications signed with the system firmware signing key can do this. Copied from this answer,

    Programmatically switching off Android phone

    You need the system key to sign your app. See this post for details;

    How to compile Android Application with system permissions


    If you're root on your device, you can follow this method to become device owner.

    First, create a file device_owner.xml with following content:

    
    
    

    Now do the following steps

    • adb push device_owner.xml /sdcard/

    • adb shell

    • su

    • cp /sdcard/device_owner.xml /data/system/

    • cd /data/system/

    • chown system:system device_owner.xml

    • reboot

    Note : Before rebooting device, make sure that you installed the application, which you are trying to make device owner. If you will not do, you will get boot animation for infinite time.

    For more info

提交回复
热议问题