In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "Android development how to achieve application level shielding status bar", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "Android development how to achieve the application level to block the status bar"!
1. Since StatusBarManager is not provided in SDK, you need to use reflection to call the method of this class
The code section is as follows:
Object service = getSystemService ("statusbar"); try {Class statusBarManager = Class.forName ("Android.app.StatusBarManager"); Method expand = statusBarManager.getMethod ("disable", int.class); expand.invoke (service, 0 × 00000001);} catch (Exception e) {e.printStackTrace ();}
Disabling the notification bar requires adding the following permissions and using the system signature:
It is mentioned in the online materials that if you do not use the system signature, the following error will be reported
Caused by: Java.lang.SecurityException: StatusBarManagerService: Neither user 10072 nor current process has android.permission.STATUS_BAR.
Before using a system signature, you need
1. Add android:sharedUserId= "android.uid.system" to the manifest node in the AndroidManifest.xml of the application
two。 Modify the Android.mk file and add LOCAL_CERTIFICATE:=platform
Let the program run into the system process
The method of enabling an application to obtain system signature permission in Android:
1. Need to compile with make in the environment of Android system source code
(1) add android:sharedUserId= "android.uid.system" to the manifest node in the AndroidManifest.xml of the application
(2) modify Android.mk file and add LOCAL_CERTIFICATE:=platform
(3) use the mm command to compile and generate APK.
two。 There is no need to compile in the system source environment
(1) add android:sharedUserId= "android.uid.system" to the manifest node in the AndroidManifest.xml of the application
(2) use eclipse to compile the APK file, and the APK file is not available
(3) Open the APK file with the compression software, and delete the CERT.SF and CERT.RSA files in the META-INF directory
(4) use the platform key of the target system to re-sign the APK file. First, find the key file, such as "build\ target\ product\ security", the following platform.pk8 and platform.x509.pem files, and then sign it with the SignApk tool provided by Android. The source code of the tool is under "build\ tools\ signapk", and the usage is "signapk platform.x509.pem platform.pk8 input.apk output.apk".
Principle:
First, add the attribute of android:sharedUserId= "android.uid.system". Multiple APK with the same User ID through SharedUserId can be configured to run in the same process. Then allocate the UID of the program to android.uid.system, that is, to let the program run in the system process, it will have the corresponding permissions.
But it is not enough to join UID. At this time, APK cannot be installed because the signature does not match. If the program wants to run in the system process, it also needs to have the platform key of the target system, which is the platform.pk8 and platform.x509.pem files in the second method above. Only after using these two key signatures can the apk be put into the system process. The LOCAL_CERTIFICATE:=platform of the first method actually uses these two key signatures.
There is also a problem, that is, the generated program is only available in the original Android system or self-compiled system, because such a system can get platform.pk8 and platform.x509.pem files, if another company's Android system can not even be installed. At present, only the data have been sorted out, and the actual development has not been carried out yet. after that, if there is a practical application of this part of the content, the final results will be collated and released.
Second, if it is a system-level application, that is, an application implanted by a mobile phone manufacturer, you can use the method of disable (int) to mask, and the parameters can be as one of the five source code parameters above. However, if it is on the application layer, the disable method cannot be used because of permission issues (if you must use it, you must have a system signature). You can use the collapse () method at this time. Both Xiaomi Lock screen and 360Lock screen use this method. The specific code is as follows:
Public void disableStatusBar () {try {Object service = getSystemService ("statusbar"); Class claz = Class.forName ("android.app.StatusBarManager"); Method expand = claz.getMethod ("collapse"); expand.invoke (service);} catch (Exception e) {e.printStackTrace ();}}
Override the onWindowfocuschanged method of activity to do the same. However, this method has serious adaptation problems, and the name of the rollback method is different in different systems, so it is very tedious to adapt all versions.
At this point, I believe you have a deeper understanding of "how to achieve application-level shielding status bar in Android development". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.