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!!