Summary of the method of shielding the status bar at the application level in Android Development

This paper describes the method of shielding the status bar at the application level in Android development. Share with you for your reference, as follows:

1、 Because statusbarmanager is not provided in the SDK, you need to use reflection to call the methods of this class

The code part is as follows:

To disable the notification bar, you need to add the following permissions and use the system signature:

It is mentioned in the online materials that if the system signature is not used, the following errors will be reported

Caused by: Java.lang.SecurityException: StatusBarManagerService: Neither user 10072 nor current process has android.permission.STATUS_ BAR.

Required before using system signature

1. Add Android: shareduserid = "Android. Uid. System" in the manifest node in the androidmanifest.xml of the application. 2. Modify the android.mk file and add local_ CERTIFICATE:=platform

Let the program run into the system process

Method of enabling application to obtain system signature permission in Android:

1. It needs to be compiled with make in the environment of Android system source code

(1) Add Android: shareduserid = "Android. Uid. System" (2) in the manifest node in the Android manifest.xml of the application, modify the android.mk file and add local_ Certificate: = platform (3) use the MM command to compile and generate APK

2. It does not need to be compiled in the system source code environment

(1) Add Android: shareduserid = "Android. Uid. System" to the manifest node in the androidmanifest.xml of the application (2) compile the APK file using eclipse, and the APK file is unavailable at this time (3) open the APK file with 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 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 Android: shareduserid = "Android. Uid. System". Multiple apks with the same user ID through shareduserid can be configured to run in the same process. Then match the uid of the program to android.uid.system, that is, to make the program run in the system process, it has the corresponding permissions.

However, adding uid is not enough. APK cannot be installed at this time because the signature is inconsistent. If the program wants to run in the system process, it also needs the platform key of the target system, which is the platform.pk8 and platform.x509.pem files in the second method above. Only after these two keys are signed can APK be put into the system process. The first method is local_ Certificate: = platform is actually signed with these two keys

There is also a problem, that is, the program generated in this way can only be used in the original Android system or the system compiled by yourself, because such a system can get the two files platform.pk8 and platform.x509.pem. If the Android system of other companies can't even be installed. At present, only the materials have been sorted out, and no actual development has been carried out. If there is practical application of this part, the final results will be sorted out and released.

2、 If it is a system level application, that is, the application implanted by the mobile phone manufacturer, you can use the disable (int) method to shield. The parameters can be one of the five parameters of the source code above. However, if it is on the application layer, the disable method cannot be used because of permission problems (if it must be used, it must have a system signature). The collapse () method can be used at this time. The current Xiaomi lock screen and 360 lock screen use this method. The specific code is as follows:

Override the onwindowfocuschanged method of the activity and perform the above operations. However, this method has serious adaptability problems. The rollback method names are different in different systems. It is very cumbersome to adapt all versions.

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.), summary of Android basic components usage, summary of Android view technology, 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
分享
二维码
< <上一篇
下一篇>>