Android 系统 reboot

/***********************************************************************
 *                        Android 系统 reboot
 * 说明:
 *     由于需要对Android系统采用自动重启测试,为了方便觉得让app接收开机
 * 广播,然后又自动关机,貌似有点蛋疼。
 *
 *                                   2016-5-18 深圳 南山平山村 曾剑锋
 **********************************************************************/


一、参考文章:
    1. Restart android device programmatically
        http://stackoverflow.com/questions/32984849/restart-android-device-programmatically
    2. INSTALL_FAILED_UPDATE_INCOMPATIBLE和INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
        http://blog.csdn.net/happyhell/article/details/5903389
    3. Android: android.content.res.Resources$NotFoundException: String resource ID #0x5
        http://stackoverflow.com/questions/11189545/android-android-content-res-resourcesnotfoundexception-string-resource-id-0x

二、解决办法:
    1. 设置权限:
        <permission android:name="android.permission.REBOOT"/>
    2. 设置系统UID:
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.aplex.autoreboot"
            android:versionCode="1"
            android:versionName="1.0" 
            android:installLocation="preferExternal"
            android:sharedUserId="android.uid.system">
    3. 重启代码:
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        pm.reboot(null);
    4. Android.mk
        LOCAL_PATH:= $(call my-dir)
        include $(CLEAR_VARS)

        LOCAL_MODULE_TAGS := optional

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

        LOCAL_PACKAGE_NAME := AutoReboot
        LOCAL_CERTIFICATE := platform

        include $(BUILD_PACKAGE)

        # Use the folloing include to make our test apk.
        include $(call all-makefiles-under,$(LOCAL_PATH))
    5. 将工程放入Android源码packages/apps目录;
    6. 删除工程中无关目录,如bin、libs等目录;
    7. 用Android自带mmm命令编译app。

三、error:
    1. error1:
        1. 错误现象:
            Installation error: INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
            Please check logcat output for more details.
            Launch canceled!
        2. 解决办法:
            采用到Android源代码中去编译apk。
    2. error2:
        1. 错误现象:
            FATAL EXCEPTION: main
            android.content.res.Resources$NotFoundException: String resource ID #0x9
                at android.content.res.Resources.getText(Resources.java:230)
                at android.widget.TextView.setText(TextView.java:3769)
                at com.aplex.autoreboot.MainActivity$1.handleMessage(MainActivity.java:25)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:5041)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:511)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                at dalvik.system.NativeStart.main(Native Method)
        2. 解决办法:
            Handler handler = new Handler() {  
                public void handleMessage(Message msg) {  
                    
                    Log.e("aplex", "handleMessage " + msg.what );
                    if (msg.what < 100) {
                        count.setText(msg.what + "");  // 这里要加上""
                    } else {
                        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                        pm.reboot(null);
                    }
                    Log.e("aplex", "handleMessage over " + msg.what );
                    super.handleMessage(msg);  
                }  
            };
    

 

posted on 2016-05-18 15:02  zengjf  阅读(1886)  评论(0编辑  收藏  举报

导航