分类: LINUX
2010-05-31 13:41:28
http://blog.chinaunix.net/u/20947/showart_1945057.html
看了网上的几个 例子,也做了一个系统启动后直接运行activity的小程序
代码贴在下面:
首先是从BroadcastReceiver
派生出一个新类,用来监听系统启动后发出的广播消息android.intent.action.BOOT_COMPLETED
。
BootReceiver.java:
Intent service =
new Intent(yourService.ACTION_START);
Intent i = new Intent(AutoRun.class.getName()); context.startService(i);
|
|
<uses-permission
android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
package="com.service.prac"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<receiver android:name=".BootReceiver"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category
android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</receiver>
<activity android:name=".FirstRun">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk
android:minSdkVersion="3" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
</manifest>