项目需要android开机自动启动一个app的界面

项目需要android开机自动启动一个app的界面,网上找了些资料,证实可用:

 
首先是在你要启动的app的 AndroidManifest.xml文件里面加下面一段代码(注意是加在application标签内):
 
< receiver  android:enabled ="true"  android:name =".BootUpReceiver"    

         android:permission ="android.permission.RECEIVE_BOOT_COMPLETED" >     

         < intent-filter >     

                 < action  android:name ="android.intent.action.BOOT_COMPLETED"  />     

                 < category  android:name ="android.intent.category.DEFAULT"  />     

         </ intent-filter >     

</ receiver >     

< uses-permission  android:name ="android.permission.RECEIVE_BOOT_COMPLETED"  />
之后在项目里面创建一个 BootUpReceiver的类( MyActivity是你自己的app的main activity ):
public  class BootUpReceiver  extends BroadcastReceiver{     
         public  void onReceive(Context context, Intent intent) {     
                Intent i =  new Intent(context, MyActivity. class);         
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);     
                context.startActivity(i);         
        }     
}
之后编译运行,再启动系统的时候,app就可以在系统启动完成之后自动运行啦

猜你喜欢

转载自yuanke.iteye.com/blog/2342645