码迷,mamicode.com
首页 > 移动开发 > 详细

Android开机程序(自定义哦!)

时间:2014-10-17 13:34:35      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   color   io   os   ar   sp   

源码下载在个人文件里面:

StartApp.rar

 

这是配置文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.startapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="com.android.startapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <receiver android:name="com.android.reserver.StartReceviver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

这是服务类

package com.android.reserver;

import com.android.startapp.MainActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
 * 继承一个服务,扑捉开机的第一个服务
 * 
 * @author Catherine.Brain
 * 
 * */
public class StartReceviver extends BroadcastReceiver {
    /** 定义一个action */
    static final String ACTION = "android.intent.action.BOOT_COMPLETED";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ACTION)) {
            Intent sayHelloIntent = new Intent(context, MainActivity.class);
            sayHelloIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(sayHelloIntent);
        }
    }

}

这里是主要类:

package com.android.startapp;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

/**
 * this is a application of the start phone
 * 
 * @author Catherine.Brain
 * */
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.activity_main);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        /** 自定义一个图片,然后加载 */
        ImageView image = new ImageView(this);
        setContentView(image);
        image.setBackgroundResource(R.drawable.ic_launcher);
        myThread.start();
    }

    Thread myThread = new Thread() {

        public void run() {
            try {
                sleep(5000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                myHandler.sendEmptyMessage(EXIT);
            }
        };
    };
    public static final int EXIT = 0x0001;
    Handler myHandler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
            case EXIT:
                /** the time is to shut down */
                System.exit(0);
                break;

            default:
                break;
            }
        };
    };
}

Android开机程序(自定义哦!)

标签:android   style   blog   http   color   io   os   ar   sp   

原文地址:http://www.cnblogs.com/Catherine-Brain/p/4030602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!