Detailed explanation of the method of prohibiting the drop-down of the status bar by Android programming

This paper describes the method of disabling the drop-down of the status bar by Android programming. Share with you for your reference, as follows:

brief introduction

When the project requires a full screen app, the drop-down of the status bar should be prohibited. This should be a common requirement, but the Android system does not provide an interface directly called by ordinary app. Then we can only find ways to add interfaces to realize this function.

Specific implementation method

1. Modify systemui

Path: = = / frameworks / base / packages / systemui / / SRC / COM / Android / systemui / statusbar / phone / phonestatusbar.java==

The status bar is disabled and released by registering a broadcast in the phonestatusbar. Java class. Its core method is to call the disable () method. Disable () is a method customized by systemui. Interested students can see its specific implementation.

Let's take a look at our specific implementation code in systemui:

Now that we have registered the hidden broadcast, let's take a look at our specific calls in the app.

Override the onresume and onpause methods in the activity to disable and disable the status bar. In addition, statusbarmanager is a hidden class, so you may not be able to import packages when calling, and an error will be reported. The simplest way is to replace them with numerical values. The corresponding relationships are listed below.

Therefore, students who cannot reference statusbarmanager use the same value. If you have source code friends, you can use the system compiled framework jar package as the Lib of the app, and you can directly use the statusbarmanager method. Its path is / out / target / common / obj / Java_ LIBRARIES/framework_ intermediates/classes.jar。 Change classes.jar to framework.jar and import the project.

Through the above steps, we know that the key is to call the disable () method in the phonestatusbar. We implement it here in the way of broadcasting. Any student with a new method can open his brain. As long as he can call disable () to disable the status bar.

2. Modify phonewindowmanager

Path: = = / frameworks / base / policy / SRC / COM / Android / internal / policy / impl / phonewindowmanager.java==

In the method of systemgesturespontereventlistener. Callbacks, a judgment function isgestureisolated() is added to judge whether its corresponding gesture operation is supported. Here is a special explanation. Find a way to use it on the Internet

When making a judgment in getsystemuivisibility(), the win obtained is not necessarily the current activity, but sometimes the status bar. Therefore, this effect is not very good. The status bar is often pulled down, so there is

One advantage of this method is that it is very direct. It is called when it is necessary to prohibit drop-down

It's OK. It's called when the prohibition is lifted

Take a look at the specific calls in the activity

Declare the corresponding permissions in androidmanifest.xml

On the Internet, you can also modify the adjustsystemuivisibilitylw method in phonewindow manager, such as:

A flag is added to adjustsystemuivisibilitylw, but the effect of this implementation is not very good, and the pull-down can still be pulled down.

To sum up, modify the method of prohibiting drop-down in phonewindowmanager or add an internal method in systemgesturespontereventlistener.callbacks. This internal method uses the form of flag bits to judge whether the status bar drop-down is supported.

3. Use the method in statusbarmanager

Because statusbarmanager is a hidden method, if you want to use it directly in the IDE, you need to import the framework jar package. How to find the framework jar is mentioned in 1. Modifying the systemui, which will not be repeated here. Direct code:

1. Declare the corresponding permissions in androidmanifest.xml

There is an article on the Internet that says it wants to make a statement

It can also be used without adding the above line of code.

2. Reference in activity

1. Use system signature and compile it into system app

Testdemonew.apk is the APK signed by the system, and then push it to the / system / APP / directory. There is not much to say about the knowledge of signature. You can find relevant information by yourself.

Let's take a look at the method of prohibiting drop-down in telephone processing in the native system. The code is as follows:

Path: = = / packages / apps / phone / SRC / COM / Android / phone / notificationmgr.java==

From this method, we know that the system disables the status bar by calling the statusbarmanager.

More readers interested in Android related content can view the special topics of this site: introduction and advanced tutorial of Android development, summary of Android multimedia operation skills (audio, video, recording, etc.), @ l_502_2@, summary of Android view skills, summary of Android layout skills and summary of Android control usage

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>