Make a small one todayProgramWhen you add a view to windowmanager, an error is always reported:
Caused by: Android. View. windowmanager $ badtokenexception: unable to add window -- token null is not for an application
This error indicates that the token is empty, so the view cannot be added. I checked the information online and they said there was a problem with the passed context object, however, I have repeatedly tested that it is normal to start widnow in the activity and add a view. Isn't it possible to start windowmanager and add a view in initiating a broadcast?
If an error occurs when adding a view, it indicates windowmanager. what parameters should be missing in layoutparams? As a result, I checked it online. It is really necessary in windowmanager. some types are added to layoutparams, and the result is self-tested. The result is OK. The specificCodeAs follows:
/*** @ Author spring sky * Email vipa1888@163.com * my name: shi mingzheng * QQ 840950105 * @ Param height * @ Param width * @ return */private layoutparams getlayoutparam (INT height, int width) {If (wmparam = NULL) {// windowmanager. add type and flag to layoutparams so that the error wmparam = new windowmanager will not occur if the token is null is sent. layoutparams (-1, 4); wmparam. windowanimations = 0; wmparam. format = pixelformat. translucent | windowmanager. layoutparams. first_system_window;} wmparam. height = height; wmparam. width = width; return wmparam ;}
In this way, you can add a view to windowmanager. Another option is to set the pop-up box, and you need to input the context of activity. This!