Power on boot main custom broadcast receive class, and need to register in the manifest file, do not register dynamically in code.
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.BROADCAST_STICKY"/>
<receiver android:name=". * * *"> <intent-filter> <action Android : Name="android.intent.action.BOOT_COMPLETED"/> <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter></receiver ><service android:name=". * * *"/>
To start writing a broadcast sink:
Public class Mybroadcastrecevice extends Broadcastreceiver { @Override publicvoid OnReceive (context context, Intent Intent) { if (Intent.getaction (). Equals (" Android.intent.action.BOOT_COMPLETED")) { // TODO:2016/9/18 Context.startservice (new Intent (context,***)); }}
Then look at the code that launches the hover box in the service:
/** * Create a hover box*/ Public voidCreatefloatingboxview () {Wmparams=( (AppContext) getapplication ()). Getmywmparams (); Mwindowmanager=(WindowManager) getapplication (). Getsystemservice (Application.window_service); Wmparams.type=WindowManager.LayoutParams.TYPE_TOAST; Wmparams.format=pixelformat.rgba_8888; Wmparams.flags=WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; Wmparams.gravity= Gravity.top |Gravity.left; Wmparams.x=0; Wmparams.y=0; Wmparams.width=WindowManager.LayoutParams.WRAP_CONTENT; Wmparams.height=WindowManager.LayoutParams.WRAP_CONTENT; Floatingboxview=NewFloatingboxview (Getapplicationcontext (), This); Mwindowmanager.addview (Floatingboxview, wmparams); //These two lines are responsible for monitoring, so ignore him .Floatingboxview.setmovelistener ( This); Floatingboxview.setallclicklistener ( This); }
Android app Boot and no permission to open the hover box