Android calls system shutdown and restart Functions
I compile package/apps/In the android source code, because the shutdown interface to be called is not open to the upper layer and cannot be called in eclipse. I mainly introduce how to call the shutdown function of android, because some permissions and other conditions for shutdown are more than those for restart during debugging. Therefore, if the shutdown function can be implemented, then restart the instance. In AndroidManifest. xml, add the statement android: sharedUserId = "android. uid. system" with the same uid as the system. Upgrade the apk to system permission. Add the statement to the version number. Then write a system permission <uses-permission android: name = "android. permission. SHUTDOWN"/>. This permission can only be used by the system-level apk, so eclipse cannot compile. Then, write two buttons in xml, one shutdown and one restart. xml is not introduced here. To restart, you need to call android. intent. action. REBOOT, which is open to the upper layer and can be called directly: case R. id. reboot_btn: Intent intent = new Intent (Intent. ACTION_REBOOT); intent. putExtra ("nowait", 1); intent. putExtra ("interval", 1); intent. putExtra ("window", 0); sendBroadcast (intent); break; then sendBroadcast can be sent only when it is a system-level apk. To implement shutdown, you need to call android. intent. action. ACTION_REQUEST_SHUTDOWN. This interface is not open to the upper layer and cannot be called in eclipse, but it is available in the source code. Therefore, no error will be reported when compiling the apk in the source code. Public static final String ACTION_REQUEST_SHUTDOWN = "android. intent. action. ACTION_REQUEST_SHUTDOWN "public static final String EXTRA_KEY_CONFIRM =" android. intent. extra. KEY_CONFIRM "Intent I = new Intent (ACTION_REQUEST_SHUTDOWN); I. putExtra (EXTRA_KEY_CONFIRM, false); I. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK); startActivity (I); I have read many blogs, all of which are written in Intent I = new Intent (Intent. ACTION_REQUEST_SHUTDOWN); I tried it, even if An error is reported during nux compilation. Therefore, you need to define a constant and then use it directly. Do not use Intent. EXTRA_KEY_CONFIRM, which must be defined by yourself, is not open to the upper layer. Because it is compiled in linux, you need to write an Android program. mk file. You can copy the file of another apk and slightly modify the copy code LOCAL_PATH :=$ (call my-dir) include $ (CLEAR_VARS) LOCAL_MODULE_TAGS: = optional # Only compile source java files in this apk. LOCAL_SRC_FILES: = $ (call all-java-files-under, src) LOCAL_SDK_VERSION: = current LOCAL_PACKAGE_NAME: = Reboot LOCAL_CERTIFICATE: = platform LOCAL_DEX_PREOPT: = false include $ (BUILD_PACKAGE) # Use the following include to make our test apk. include $ (call all-makefiles-under, $ (LOCAL_PATH) copy the code. I don't know much about mk files. Let's talk about the key: LOCAL_PACKAGE_NAME: = If the project name is 4.0 or later, you must add LOCAL_DEX_PREOPT: = false to compile and generate the apk file. If the default value is true, the LOCAL_CERTIFICATE statement must be added for independent installation and running: = platform: The system permission is obtained. Someone says they want to delete the bin directory. The specific function is not cleared. Anyway, I deleted the Directory and added it to the root directory of the android source code. build/envsetup. sh and then lunch a version to go to the directory where the project has mk files for execution mm