1.要做的就是监听系统发出的broadcast
public class FlorenceText extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
start(context);
}
}
}
2.在AndroidMenifest.xml里还要将receiver加上, 并写明程序的入口就是FlorenceTest
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name=".main.FlorenceTest"
android:exported="true"
android:process=":remote">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
</application>
这样,程序就可以在开机时自动运行了
本文介绍如何在Android中创建开机自启动的应用程序。通过定义一个BroadcastReceiver子类并在AndroidManifest.xml中配置相应的<intent-filter>,使得应用能在设备启动完成时自动运行。
2万+

被折叠的 条评论
为什么被折叠?



