主要思路来自网络!

1、需要源码才能编译

2、修改项目的Android.mk文件,添加

LOCAL_CERTIFICATE := platform

3、AndroidManifest.xml中添加权限

3.1 manifest标签中添加

android:sharedUserId="android.uid.system"

3.2 使用权限

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

4、java代码

// 创建Intent// 如果是要重启,则使用Intent.ACTION_REBOOTIntent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);// 设置是否需要用户确认,若不需要,可以不设置或设置为falseintent.putExtra(Intent.EXTRA_KEY_CONFIRM, true);// 当作新任务执行intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// 启动startActivity(intent);

据说还可以使用Broadcast的方式调用,不过我试了一下,窗口是出来了,但一直停在关机的进度条那。不知道是不是机子的问题。

代码如下:

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

更多相关文章

  1. Android使用Asynchronous Http Client完成登录保存cookie的问题
  2. SwipeRefreshLayout+RecyclerView实现下拉刷新上拉加载功能
  3. android 项目中规范使用SharedPreferences
  4. Android(安卓)7.0 使用FileProvider 在应用间共享文件
  5. Android使用AsyncTask下载图片,最好使用WeakReference
  6. android studio里面的svn基本使用
  7. 箭头函数的基础使用
  8. NPM 和webpack 的基础使用
  9. Python list sort方法的具体使用

随机推荐

  1. Ubuntu Android 的 USB 调试模式
  2. 基于 Android 的学习之旅-----环境搭建
  3. Android自底部平滑向上滑出面板的Android
  4. Cocos2d-x2.1.4的android环境配置及使用
  5. Android 开发入门问题集:启动模拟器、安装
  6. Android NDK带来什么(转)
  7. Android 中文 API(123) ―― AbsListView(
  8. android 精典博文内容推荐
  9. Android实现在xml文件中引用自定义View的
  10. Android 视图 状态栏