android代码实现关机

时间:2024-01-18 08:25:50

1、API没有开放,需要提升为syetem app级别!

2、android 模块编译,mm 命令

2.1、先进入顶层  source build/envsetup.sh

2.2、进入目录   mm

3、android.mk

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := Shutdown

LOCAL_CERTIFICATE := platform

include $(BUILD_PACKAGE)

# Use the folloing include to make our test apk.

include $(call all-makefiles-under,$(LOCAL_PATH))

4、源码

Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);

intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);

5、注意权限

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.shutdown.ft"

android:versionCode="1"

android:sharedUserId="android.uid.system"

android:versionName="1.0">

<application android:icon="@drawable/icon" android:label="@string/app_name">

<activity android:name=".Shutdown"

android:label="@string/app_name">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

<uses-sdk android:minSdkVersion="7" />

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

</manifest>