zoukankan      html  css  js  c++  java
  • Android开机程序(自定义哦!)

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

    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;
                }
            };
        };
    }
    一切只是为了充实自己!!stay hungry and stay foolish!!
  • 相关阅读:
    Java 异常处理
    Java Scanner 类
    Java 流(Stream)、文件(File)和IO
    Java 方法
    'javac' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
    Java 正则表达式
    nginx配置ssl证书
    Windows 查看端口、根据pid查找引用程序
    scp复制文件到另外一台服务器
    CentOS安装jdk SE 1.8 JDK与OpenJDK的区别
  • 原文地址:https://www.cnblogs.com/Catherine-Brain/p/4030602.html
Copyright © 2011-2022 走看看