android代码实现关机

               

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> 

转载于:https://www.cnblogs.com/cm1943/archive/2011/10/09/2204074.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值