Android WindowManager suspended windows: No need to apply for permission to implement suspension

Source: Internet
Author: User

??

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.