AndroidManifest.xml 加上权限

<manifest ...... android:sharedUserId="android.uid.system"/>

<uses-permission android:name="android.permission.SHUTDOWN" />

 

代码

关机:

Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);

intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);

重启:

Intent i = new Intent(Intent.ACTION_REBOOT);
i.putExtra("nowait", 1);
i.putExtra("interval", 1);
i.putExtra("window", 0);
sendBroadcast(i); 

 

Android.mk 加一行

LOCAL_CERTIFICATE := platform

 

须使用Linux mm命令来编译apk

关机的相关并没有开放 所以直接在eclipse里面是会报错的

相关文章:

  • 2022-02-13
  • 2021-12-27
  • 2021-06-26
  • 2022-12-23
  • 2021-05-03
  • 2022-02-08
  • 2021-05-26
  • 2021-11-12
猜你喜欢
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
  • 2022-12-23
  • 2021-04-18
  • 2022-12-23
  • 2021-05-29
相关资源
相似解决方案