BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / mobile-terminal-at / #3273同步于 2011/5/14
该镜像源已超过 30 天没有更新,可能在源站已被删除。
MobileTerminalAT机器人发帖

如何在android程序中实现系统关机或重启

mixianghang
2011/5/14镜像同步6 回复
我想在android java代码里实现android 系统的关闭及重启功能,如何实现?
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
ingenious机器人#1 · 2011/5/14
其实你能百度出来的... 不过这次我替你百度了下,顺便学习. 关机: In frameworks/base/services/java/com/android/server/BatteryService.java Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN); intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(intent); 重启: Intent i = new Intent(Intent.ACTION_REBOOT); i.putExtra("nowait", 1); i.putExtra("interval", 1); i.putExtra("window", 0); sendBroadcast(i); 注意添加权限。 http://topic.csdn.net/u/20100423/15/34a5ca3d-df13-4056-8e62-55f6c4c5e412.html
mixianghang机器人#2 · 2011/5/15
我在发帖之前就尝试过你这种方法,运行虚拟机,直接出错
mixianghang机器人#3 · 2011/5/15
我在mainifest文件添加了权限,但不知道对不对 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ccm.romote.control" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.REBOOT" /> </manifest>
mixianghang机器人#4 · 2011/5/15
这是我在网上找到的方法,但是在模拟器中运行后出现如下错误: Installation error: INSTALL_FAILED_SHARED_USER_INCOMPATIBLE [2011-05-15 16:32:58 - CCMromoteControl] Please check logcat output for more details. [2011-05-15 16:32:58 - CCMromoteControl] Launch canceled! public class ShutDownAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent i = new Intent(Intent.ACTION_REBOOT); i.setAction(Intent.ACTION_REBOOT); i.putExtra("nowait", 1); i.putExtra("interval", 1); i.putExtra("window", 0); sendBroadcast(i); } } AndroidMainifest: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ccm.romote.control" android:versionCode="1" android:versionName="1.0" android:sharedUserId="android.uid.system" > <uses-permission android:name="android.permission.REBOOT" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ShutDownAndroid" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <uses-permission android:name="android.permission.REBOOT" /> </intent-filter> </activity> </application> </manifest>
ingenious机器人#5 · 2011/5/15
android:sharedUserId="android.uid.system" 没有这句话权限不够 有了这句话就不能用sdk编译了,得在源码环境下添加Android.mk,然后用mmm编译..
Zy机器人#6 · 2011/5/16
那这样在应用中只能用系统签名不能用自己签名了? 【 在 ingenious 的大作中提到: 】 : 发信站: 北邮人论坛(2011-05-15 18:53:20) : android:sharedUserId="android.uid.system" : 没有这句话权限不够 : ................... - 本文通过BYR Android客户端1.52发布