reboot:
Intent i = new Intent( Intent.ACTION_REBOOT);
intent.putExtra("nowait", 1);
intent.putExtra("interval", 1);
intent.putExtra("window", 0);
sendBroadcast( i );
shutdown:
Intent i
= new Intent( Intent.ACTION_SHUTDOWN);
sendBroadcast( i );public class RebootSystem extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("U0fly ---======>", "onCreate");
Button btn = (Button)findViewById(R.id.Button01);
btn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("U0fly ---======>", "onClick");
rebootAndroid();
}
});
}
private void rebootAndroid()
{
Intent intent = new Intent(Intent.ACTION_REBOOT);
intent.putExtra("nowait", 1);
intent.putExtra("interval", 1);
intent.putExtra("window", 0);
sendBroadcast(intent);
}
}
AndroidManifest.xml:
= " android.uid.system " >
.....
android: sharedUserId
....
< uses - permission android: name = " android.permission.RECEIVE_BOOT_COMPLETED " >
Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := user
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := RebootSystem
LOCAL_CERTIFICATE := platform
#LOCAL_OVERRIDES_PACKAGES := Home
include $(BUILD_PACKAGE)
# additionally, build tests in sub-folders in a separate .apk
include $(call all-makefiles-under,$(LOCAL_PATH))
Android 自己的程序中添加系统重启的提示框
最新推荐文章于 2024-09-23 23:45:42 发布
本文介绍了一个简单的Android应用程序,用于实现设备的重启和关机操作。通过发送特定的广播Intent,可以触发系统的重启或关机流程。需要注意的是,此类操作通常需要特殊权限,并且仅限系统应用使用。
3333

被折叠的 条评论
为什么被折叠?



