1、首先我们还是新建一个activity来作为开机运行时显示的欢迎界面。
![Android开发学习:[31]android开机启动app](https://exp-picture.cdn.bcebos.com/0fb94656d53da824bd532a61306651598440cb0d.jpg)
2、然后我们在包下面新建一个StartUpReceiver类作为接受器,继承自BroadcastReceiver。代码如下:public class StartUpReceiver extends BroadcastReceiver { public StartUpReceiver() { } @Override public void onReceive(Context context, Intent intent) { Intent intent2=new Intent(context,MainActivity12.class); context.startActivity(intent2); }}
![Android开发学习:[31]android开机启动app](https://exp-picture.cdn.bcebos.com/d9a8d2d2bb665159ecfaf6998fe23ea23b42c70d.jpg)
3、然后我们在欢迎界面中的TextView控件的字体稍微改一下,显得亲和一些。<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.basillee.asus.demo.MainActivity12"> <TextView android:text="欢迎进入开机启动页面" android:layout_width="wrap_content" android:layout_height="wrap_content" /></RelativeLayout>
![Android开发学习:[31]android开机启动app](https://exp-picture.cdn.bcebos.com/84010e2a04e23ea257f846c92b10bc33ed38c30d.jpg)
4、最后我们就需要在清单文件manifast.xml里面注册Reciver并将其intent-filter的action指定到android.intent.action.BOOT_COMPLETED;代码如下: <receiver android:name=".StartUpReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"></action> <category android:name="android.intent.category.DEFAULT"></category> </intent-filter> </receiver>
![Android开发学习:[31]android开机启动app](https://exp-picture.cdn.bcebos.com/a13bbe10bc33ec384601ff5c295f0c14c37b3c12.jpg)
5、然后我们点击Android Studio上面的运行按钮,进行测试。
![Android开发学习:[31]android开机启动app](https://exp-picture.cdn.bcebos.com/18aebc5f0c14c27ba538603a2a46b7b1eff93912.jpg)
6、最后我们就可以看到测试结果如我们所预期的一样了,当然最好采用真机测试。
![Android开发学习:[31]android开机启动app](https://exp-picture.cdn.bcebos.com/87c8bf46b7b1eef90307aacfbfb33c4132ba3212.jpg)