??
Android WindowManager suspended windows: No need to apply for permission to implement suspension
Appendix 1 describes the hover windows on the Android platform Windowmanager,windowmanager hover windows can hover over the desktop window on Android devices, but the use of WindowManager must first apply for permission, In some custom-built Android operating systems, it is possible to windowmanager the permissions of the suspended Windows, which makes WindowManager-based app functionality difficult to implement.
However, you can work around the type of WindowManager by setting the WindowManager type to WindowManager.LayoutParams.TYPE_TOAST, Therefore, you can use WindowManager without applying for WindowManager suspended window permission.
Write an example. A simple main activity that does not require any layout:
Package Zhangphil.demo;import Android.graphics.color;import Android.support.v7.app.appcompatactivity;import Android.os.bundle;import Android.view.gravity;import Android.view.view;import Android.view.WindowManager;import Android.widget.textview;import Android.widget.toast;public class Mainactivity extends Appcompatactivity {@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); TextView TextView = new TextView (this); Textview.setgravity (Gravity.center); Textview.setbackgroundcolor (Color.Black); Textview.settext ("Zhang Phil @ csdn"); Textview.settextsize (10); Textview.settextcolor (color.red); The type is type_toast, like a regular Android TOAST. In this way, you do not need to apply for suspended window permissions. Windowmanager.layoutparams params = new Windowmanager.layoutparams (WindowManager.LayoutParams.TYPE_TOAST); The window focus is not first obtained after initialization. Does not interfere with the click and touch events of other parts on the device. Params.flags = WindowManager. layoutparams.flag_not_focusable; Params.width = WindowManager.LayoutParams.MATCH_PARENT; Params.height = 300; Params.gravity=gravity.bottom; Textview.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) { Toast.maketext (Getapplication (), "Do not require permission for a suspended window implementation", Toast.length_long). Show (); } }); WindowManager WindowManager = (WindowManager) getapplication (). Getsystemservice (Getapplication (). Window_service); Windowmanager.addview (TextView, params); }}
Code Run Result:
Through such a strategy to achieve windowmanager, can do a lot of things, such as Android common music class app bottom Play bar, you can consider using this method to achieve. Make a music play bar on the top of the app for a long-term presence via WindowManager.
Appendix:
1, "Android windowmanager hover Window" Link: http://blog.csdn.net/zhangphil/article/details/50382966
2, "Android Desktop widget Appwidget (1)" Link: http://blog.csdn.net/zhangphil/article/details/50457355
3, "Android Desktop widget Appwidget (2)" Link: http://blog.csdn.net/zhangphil/article/details/50461944
4, "Android Desktop widget Appwidget: Music player Desktop Control Widget widget (3)" Link: http://blog.csdn.net/zhangphil/article/details/50466844
Android WindowManager suspended windows: No need to apply for permission to implement suspension