How to Reboot phone programmatically?

前端 未结 5 1422
情深已故
情深已故 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条回答
  •  -上瘾入骨i
    2021-01-17 05:30

    This is my answer and code that might help you:

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.REBOOT)
                    != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.REBOOT}, 1);
                if(ContextCompat.checkSelfPermission(this, Manifest.permission.REBOOT)
                        != PackageManager.PERMISSION_GRANTED) {
                    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                    pm.reboot(null);
                }
            } else {
                PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                pm.reboot(null);
            }
    

提交回复
热议问题